Search in sources :

Example 96 with FileUtils

use of com.spectralogic.ds3autogen.api.FileUtils in project ds3_autogen by SpectraLogic.

the class GoFunctionalTests method replicatePutJob.

@Test
public void replicatePutJob() throws IOException, TemplateModelException {
    // Test for request with string payload
    final String requestName = "ReplicatePutJobSpectraS3Request";
    final FileUtils fileUtils = mock(FileUtils.class);
    final GoTestCodeUtil codeGenerator = new GoTestCodeUtil(fileUtils, requestName, "MasterObjectList");
    codeGenerator.generateCode(fileUtils, "/input/replicatePutJob.xml");
    // Verify Request file was generated
    final String requestCode = codeGenerator.getRequestCode();
    CODE_LOGGER.logFile(requestCode, FileTypeToLog.REQUEST);
    assertTrue(hasContent(requestCode));
    assertFalse(requestCode.contains("\"strconv\""));
    //content is in request struct
    assertTrue(requestCode.contains("content networking.ReaderWithSizeDecorator"));
    //content is assigned a stream
    assertTrue(requestCode.contains("content: buildStreamFromString(requestPayload),"));
    assertTrue(returnsStream(requestName, requestCode));
    // Verify Response file was generated
    final String responseCode = codeGenerator.getResponseCode();
    CODE_LOGGER.logFile(responseCode, FileTypeToLog.RESPONSE);
    assertTrue(hasContent(responseCode));
    assertTrue(responseCode.contains("MasterObjectList *MasterObjectList"));
    assertFalse(responseCode.contains("`xml:\"MasterObjectList\"`"));
    assertTrue(responseCode.contains("func NewReplicatePutJobSpectraS3Response(webResponse networking.WebResponse) (*ReplicatePutJobSpectraS3Response, error) {"));
    assertTrue(responseCode.contains("expectedStatusCodes := []int { 200, 204 }"));
    assertTrue(responseCode.contains("var body ReplicatePutJobSpectraS3Response"));
    assertTrue(responseCode.contains("if err := readResponseBody(webResponse, &body.MasterObjectList); err != nil {"));
    assertTrue(responseCode.contains("return &body, nil"));
    assertTrue(responseCode.contains("return &ReplicatePutJobSpectraS3Response{}, nil"));
    // Verify response payload type file was not generated
    final String typeCode = codeGenerator.getTypeCode();
    CODE_LOGGER.logFile(typeCode, FileTypeToLog.MODEL);
    assertTrue(hasContent(typeCode));
    // Verify that the client code was generated
    final String client = codeGenerator.getClientCode(HttpVerb.PUT);
    CODE_LOGGER.logFile(client, FileTypeToLog.CLIENT);
    assertTrue(hasContent(client));
    assertTrue(client.contains("func (client *Client) ReplicatePutJobSpectraS3(request *models.ReplicatePutJobSpectraS3Request) (*models.ReplicatePutJobSpectraS3Response, error) {"));
    assertTrue(client.contains("networkRetryDecorator := networking.NewNetworkRetryDecorator(&(client.netLayer), client.clientPolicy.maxRetries)"));
    assertTrue(client.contains("response, requestErr := networkRetryDecorator.Invoke(request)"));
}
Also used : FileUtils(com.spectralogic.ds3autogen.api.FileUtils) GoTestCodeUtil(com.spectralogic.ds3autogen.go.utils.GoTestCodeUtil) Test(org.junit.Test)

Example 97 with FileUtils

use of com.spectralogic.ds3autogen.api.FileUtils in project ds3_autogen by SpectraLogic.

the class GoFunctionalTests method getJobToReplicate.

@Test
public void getJobToReplicate() throws IOException, TemplateModelException {
    // Test for request with string response payload
    final String requestName = "GetJobToReplicateSpectraS3Request";
    final FileUtils fileUtils = mock(FileUtils.class);
    final GoTestCodeUtil codeGenerator = new GoTestCodeUtil(fileUtils, requestName);
    codeGenerator.generateCode(fileUtils, "/input/getJobToReplicate.xml");
    // Verify Request file was generated
    final String requestCode = codeGenerator.getRequestCode();
    CODE_LOGGER.logFile(requestCode, FileTypeToLog.REQUEST);
    assertTrue(hasContent(requestCode));
    assertFalse(requestCode.contains("\"strconv\""));
    assertTrue(requestCode.contains("jobId string"));
    assertTrue(requestCode.contains("jobId: jobId,"));
    assertTrue(requestCode.contains("\"/_rest_/job/\" + getJobToReplicateSpectraS3Request.jobId"));
    // Verify Response file was generated
    final String responseCode = codeGenerator.getResponseCode();
    CODE_LOGGER.logFile(responseCode, FileTypeToLog.RESPONSE);
    assertTrue(hasContent(responseCode));
    assertTrue(responseCode.contains("Content string"));
    assertTrue(responseCode.contains("func NewGetJobToReplicateSpectraS3Response(webResponse networking.WebResponse) (*GetJobToReplicateSpectraS3Response, error) {"));
    assertTrue(responseCode.contains("expectedStatusCodes := []int { 200 }"));
    assertTrue(responseCode.contains("return &GetJobToReplicateSpectraS3Response{Content: content}, nil"));
    // Verify response payload type file was not generated
    final String typeCode = codeGenerator.getTypeCode();
    CODE_LOGGER.logFile(typeCode, FileTypeToLog.MODEL);
    assertTrue(isEmpty(typeCode));
    // Verify that the client code was generated
    final String client = codeGenerator.getClientCode(HttpVerb.GET);
    CODE_LOGGER.logFile(client, FileTypeToLog.CLIENT);
    assertTrue(hasContent(client));
    assertTrue(client.contains("func (client *Client) GetJobToReplicateSpectraS3(request *models.GetJobToReplicateSpectraS3Request) (*models.GetJobToReplicateSpectraS3Response, error) {"));
    assertTrue(client.contains("networkRetryDecorator := networking.NewNetworkRetryDecorator(&(client.netLayer), client.clientPolicy.maxRetries)"));
    assertTrue(client.contains("httpRedirectDecorator := networking.NewHttpTempRedirectDecorator(&networkRetryDecorator, client.clientPolicy.maxRedirect)"));
    assertTrue(client.contains("response, requestErr := httpRedirectDecorator.Invoke(request)"));
}
Also used : FileUtils(com.spectralogic.ds3autogen.api.FileUtils) GoTestCodeUtil(com.spectralogic.ds3autogen.go.utils.GoTestCodeUtil) Test(org.junit.Test)

Example 98 with FileUtils

use of com.spectralogic.ds3autogen.api.FileUtils in project ds3_autogen by SpectraLogic.

the class GoFunctionalTests method simpleRequestWithPayload.

@Test
public void simpleRequestWithPayload() throws IOException, TemplateModelException {
    final String requestName = "SimpleWithPayloadRequest";
    final FileUtils fileUtils = mock(FileUtils.class);
    final GoTestCodeUtil codeGenerator = new GoTestCodeUtil(fileUtils, requestName, "Bucket");
    codeGenerator.generateCode(fileUtils, "/input/simpleRequestWithPayload.xml");
    // Verify Request file was generated
    final String requestCode = codeGenerator.getRequestCode();
    CODE_LOGGER.logFile(requestCode, FileTypeToLog.REQUEST);
    assertTrue(hasContent(requestCode));
    assertTrue(requestCode.contains("\"strconv\""));
    // Verify Response file was generated
    final String responseCode = codeGenerator.getResponseCode();
    CODE_LOGGER.logFile(responseCode, FileTypeToLog.RESPONSE);
    assertTrue(hasContent(responseCode));
    assertTrue(responseCode.contains("Bucket Bucket"));
    assertFalse(responseCode.contains("`xml:\"Bucket\"`"));
    assertTrue(responseCode.contains("func NewSimpleWithPayloadResponse(webResponse networking.WebResponse) (*SimpleWithPayloadResponse, error) {"));
    assertTrue(responseCode.contains("expectedStatusCodes := []int { 204 }"));
    assertTrue(responseCode.contains("var body SimpleWithPayloadResponse"));
    assertTrue(responseCode.contains("if err := readResponseBody(webResponse, &body.Bucket); err != nil {"));
    assertTrue(responseCode.contains("return &body, nil"));
    // Verify response payload type file was not generated
    final String typeCode = codeGenerator.getTypeCode();
    CODE_LOGGER.logFile(typeCode, FileTypeToLog.MODEL);
    assertTrue(hasContent(typeCode));
    // Verify that the client code was generated
    final String client = codeGenerator.getClientCode(HttpVerb.DELETE);
    CODE_LOGGER.logFile(client, FileTypeToLog.CLIENT);
    assertTrue(hasContent(client));
    assertTrue(client.contains("func (client *Client) SimpleWithPayload(request *models.SimpleWithPayloadRequest) (*models.SimpleWithPayloadResponse, error) {"));
    assertTrue(client.contains("networkRetryDecorator := networking.NewNetworkRetryDecorator(&(client.netLayer), client.clientPolicy.maxRetries)"));
    assertTrue(client.contains("response, requestErr := networkRetryDecorator.Invoke(request)"));
}
Also used : FileUtils(com.spectralogic.ds3autogen.api.FileUtils) GoTestCodeUtil(com.spectralogic.ds3autogen.go.utils.GoTestCodeUtil) Test(org.junit.Test)

Example 99 with FileUtils

use of com.spectralogic.ds3autogen.api.FileUtils in project ds3_autogen by SpectraLogic.

the class GoFunctionalTests method putMultiPartUploadPart.

@Test
public void putMultiPartUploadPart() throws IOException, TemplateModelException {
    // This tests correct generation of request with ReaderWithSizeDecorator payload
    final String requestName = "PutMultiPartUploadPartRequest";
    final FileUtils fileUtils = mock(FileUtils.class);
    final GoTestCodeUtil codeGenerator = new GoTestCodeUtil(fileUtils, requestName);
    codeGenerator.generateCode(fileUtils, "/input/putMultiPartUploadPart.xml");
    // Verify Request file was generated
    final String requestCode = codeGenerator.getRequestCode();
    CODE_LOGGER.logFile(requestCode, FileTypeToLog.REQUEST);
    assertTrue(hasContent(requestCode));
    // test request imports
    assertTrue(requestCode.contains("\"strconv\""));
    assertTrue(requestCode.contains("\"net/url\""));
    assertTrue(requestCode.contains("\"net/http\""));
    assertTrue(requestCode.contains("\"ds3/networking\""));
    // test request struct
    assertTrue(requestCode.contains("bucketName string"));
    assertTrue(requestCode.contains("objectName string"));
    assertTrue(requestCode.contains("partNumber int"));
    assertTrue(requestCode.contains("uploadId string"));
    assertTrue(requestCode.contains("content networking.ReaderWithSizeDecorator"));
    // test constructor
    assertTrue(requestCode.contains("func NewPutMultiPartUploadPartRequest(bucketName string, objectName string, content networking.ReaderWithSizeDecorator, partNumber int, uploadId string) *PutMultiPartUploadPartRequest {"));
    assertTrue(requestCode.contains("bucketName: bucketName,"));
    assertTrue(requestCode.contains("objectName: objectName,"));
    assertTrue(requestCode.contains("partNumber: partNumber,"));
    assertTrue(requestCode.contains("uploadId: uploadId,"));
    assertTrue(requestCode.contains("content: content,"));
    // test path
    assertTrue(requestCode.contains("return \"/\" + putMultiPartUploadPartRequest.bucketName + \"/\" + putMultiPartUploadPartRequest.objectName"));
    // test content stream
    assertTrue(requestCode.contains("func (putMultiPartUploadPartRequest *PutMultiPartUploadPartRequest) GetContentStream() networking.ReaderWithSizeDecorator {"));
    assertTrue(requestCode.contains("return putMultiPartUploadPartRequest.content"));
    // Verify Response file was generated
    final String responseCode = codeGenerator.getResponseCode();
    CODE_LOGGER.logFile(responseCode, FileTypeToLog.RESPONSE);
    assertTrue(hasContent(responseCode));
    assertTrue(responseCode.contains("func NewPutMultiPartUploadPartResponse(webResponse networking.WebResponse) (*PutMultiPartUploadPartResponse, error) {"));
    assertTrue(responseCode.contains("expectedStatusCodes := []int { 200 }"));
    assertTrue(responseCode.contains("return &PutMultiPartUploadPartResponse{}, nil"));
    // Verify response payload type file was not generated
    final String typeCode = codeGenerator.getTypeCode();
    CODE_LOGGER.logFile(typeCode, FileTypeToLog.MODEL);
    assertTrue(isEmpty(typeCode));
    // Verify that the client code was generated
    final String client = codeGenerator.getClientCode(HttpVerb.PUT);
    CODE_LOGGER.logFile(client, FileTypeToLog.CLIENT);
    assertTrue(hasContent(client));
    assertTrue(client.contains("func (client *Client) PutMultiPartUploadPart(request *models.PutMultiPartUploadPartRequest) (*models.PutMultiPartUploadPartResponse, error) {"));
    assertTrue(client.contains("networkRetryDecorator := networking.NewNetworkRetryDecorator(&(client.netLayer), client.clientPolicy.maxRetries)"));
    assertTrue(client.contains("response, requestErr := networkRetryDecorator.Invoke(request)"));
}
Also used : FileUtils(com.spectralogic.ds3autogen.api.FileUtils) GoTestCodeUtil(com.spectralogic.ds3autogen.go.utils.GoTestCodeUtil) Test(org.junit.Test)

Example 100 with FileUtils

use of com.spectralogic.ds3autogen.api.FileUtils in project ds3_autogen by SpectraLogic.

the class GoFunctionalTests method getAzureDataReplicationRules.

@Test
public void getAzureDataReplicationRules() throws IOException, TemplateModelException {
    // This tests generation of request with "type" optional parameter keyword conflict
    final String requestName = "GetAzureDataReplicationRulesSpectraS3Request";
    final FileUtils fileUtils = mock(FileUtils.class);
    final GoTestCodeUtil codeGenerator = new GoTestCodeUtil(fileUtils, requestName, "AzureDataReplicationRule");
    codeGenerator.generateCode(fileUtils, "/input/getAzureDataReplicationRules.xml");
    // Verify Request file was generated
    final String requestCode = codeGenerator.getRequestCode();
    CODE_LOGGER.logFile(requestCode, FileTypeToLog.REQUEST);
    assertTrue(hasContent(requestCode));
    // test request imports
    assertTrue(requestCode.contains("\"strconv\""));
    assertTrue(requestCode.contains("\"net/url\""));
    assertTrue(requestCode.contains("\"net/http\""));
    assertTrue(requestCode.contains("\"ds3/networking\""));
    // test request struct
    assertTrue(requestCode.contains("dataPolicyId string"));
    assertTrue(requestCode.contains("pageLength int"));
    assertTrue(requestCode.contains("pageOffset int"));
    assertTrue(requestCode.contains("pageStartMarker string"));
    assertTrue(requestCode.contains("replicateDeletes bool"));
    assertTrue(requestCode.contains("state DataPlacementRuleState"));
    assertTrue(requestCode.contains("targetId string"));
    assertTrue(requestCode.contains("dataReplicationRuleType DataReplicationRuleType"));
    // test constructor and with-constructors
    assertTrue(requestCode.contains("func (getAzureDataReplicationRulesSpectraS3Request *GetAzureDataReplicationRulesSpectraS3Request) WithDataPolicyId(dataPolicyId string) *GetAzureDataReplicationRulesSpectraS3Request {"));
    assertTrue(requestCode.contains("func (getAzureDataReplicationRulesSpectraS3Request *GetAzureDataReplicationRulesSpectraS3Request) WithPageLength(pageLength int) *GetAzureDataReplicationRulesSpectraS3Request {"));
    assertTrue(requestCode.contains("func (getAzureDataReplicationRulesSpectraS3Request *GetAzureDataReplicationRulesSpectraS3Request) WithPageOffset(pageOffset int) *GetAzureDataReplicationRulesSpectraS3Request {"));
    assertTrue(requestCode.contains("func (getAzureDataReplicationRulesSpectraS3Request *GetAzureDataReplicationRulesSpectraS3Request) WithPageStartMarker(pageStartMarker string) *GetAzureDataReplicationRulesSpectraS3Request {"));
    assertTrue(requestCode.contains("func (getAzureDataReplicationRulesSpectraS3Request *GetAzureDataReplicationRulesSpectraS3Request) WithReplicateDeletes(replicateDeletes bool) *GetAzureDataReplicationRulesSpectraS3Request {"));
    assertTrue(requestCode.contains("func (getAzureDataReplicationRulesSpectraS3Request *GetAzureDataReplicationRulesSpectraS3Request) WithState(state DataPlacementRuleState) *GetAzureDataReplicationRulesSpectraS3Request {"));
    assertTrue(requestCode.contains("func (getAzureDataReplicationRulesSpectraS3Request *GetAzureDataReplicationRulesSpectraS3Request) WithTargetId(targetId string) *GetAzureDataReplicationRulesSpectraS3Request {"));
    assertTrue(requestCode.contains("func (getAzureDataReplicationRulesSpectraS3Request *GetAzureDataReplicationRulesSpectraS3Request) WithDataReplicationRuleType(dataReplicationRuleType DataReplicationRuleType) *GetAzureDataReplicationRulesSpectraS3Request {"));
    assertTrue(requestCode.contains("func (getAzureDataReplicationRulesSpectraS3Request *GetAzureDataReplicationRulesSpectraS3Request) WithLastPage() *GetAzureDataReplicationRulesSpectraS3Request {"));
    // Verify Response file was generated
    final String responseCode = codeGenerator.getResponseCode();
    CODE_LOGGER.logFile(responseCode, FileTypeToLog.RESPONSE);
    assertTrue(hasContent(responseCode));
    assertTrue(responseCode.contains("AzureDataReplicationRuleList AzureDataReplicationRuleList"));
    assertFalse(responseCode.contains("`xml:\"AzureDataReplicationRuleList\"`"));
    assertTrue(responseCode.contains("func NewGetAzureDataReplicationRulesSpectraS3Response(webResponse networking.WebResponse) (*GetAzureDataReplicationRulesSpectraS3Response, error) {"));
    assertTrue(responseCode.contains("expectedStatusCodes := []int { 200 }"));
    assertTrue(responseCode.contains("if err := readResponseBody(webResponse, &body.AzureDataReplicationRuleList); err != nil {"));
    assertTrue(responseCode.contains("return &body, nil"));
    // Verify response payload type file was not generated
    final String typeCode = codeGenerator.getTypeCode();
    CODE_LOGGER.logFile(typeCode, FileTypeToLog.MODEL);
    assertTrue(hasContent(typeCode));
    // Verify that the client code was generated
    final String client = codeGenerator.getClientCode(HttpVerb.GET);
    CODE_LOGGER.logFile(client, FileTypeToLog.CLIENT);
    assertTrue(hasContent(client));
    assertTrue(client.contains("func (client *Client) GetAzureDataReplicationRulesSpectraS3(request *models.GetAzureDataReplicationRulesSpectraS3Request) (*models.GetAzureDataReplicationRulesSpectraS3Response, error) {"));
    assertTrue(client.contains("networkRetryDecorator := networking.NewNetworkRetryDecorator(&(client.netLayer), client.clientPolicy.maxRetries)"));
    assertTrue(client.contains("httpRedirectDecorator := networking.NewHttpTempRedirectDecorator(&networkRetryDecorator, client.clientPolicy.maxRedirect)"));
    assertTrue(client.contains("response, requestErr := httpRedirectDecorator.Invoke(request)"));
}
Also used : FileUtils(com.spectralogic.ds3autogen.api.FileUtils) GoTestCodeUtil(com.spectralogic.ds3autogen.go.utils.GoTestCodeUtil) Test(org.junit.Test)

Aggregations

FileUtils (com.spectralogic.ds3autogen.api.FileUtils)113 Test (org.junit.Test)112 Arguments (com.spectralogic.ds3autogen.api.models.Arguments)46 TestGenerateCode (com.spectralogic.ds3autogen.net.utils.TestGenerateCode)34 TestGeneratedCode (com.spectralogic.ds3autogen.java.utils.TestGeneratedCode)30 GoTestCodeUtil (com.spectralogic.ds3autogen.go.utils.GoTestCodeUtil)19 BaseParseResponse (com.spectralogic.ds3autogen.java.models.parseresponse.BaseParseResponse)18 TestGeneratedModelCode (com.spectralogic.ds3autogen.java.utils.TestGeneratedModelCode)11 TestPythonGeneratedCode (com.spectralogic.ds3autogen.python.utils.TestPythonGeneratedCode)10 EmptyParseResponse (com.spectralogic.ds3autogen.java.models.parseresponse.EmptyParseResponse)5 TypeContent (com.spectralogic.ds3autogen.python.model.type.TypeContent)5 TypeElementList (com.spectralogic.ds3autogen.python.model.type.TypeElementList)5 ImmutableList (com.google.common.collect.ImmutableList)4 Ds3DocSpec (com.spectralogic.ds3autogen.api.models.docspec.Ds3DocSpec)4 Element (com.spectralogic.ds3autogen.java.models.Element)4 TestGeneratedComponentResponseCode (com.spectralogic.ds3autogen.java.utils.TestGeneratedComponentResponseCode)4 Ds3DocSpecImpl (com.spectralogic.ds3autogen.docspec.Ds3DocSpecImpl)3 TypeElement (com.spectralogic.ds3autogen.python.model.type.TypeElement)3 Ds3SpecParserImpl (com.spectralogic.ds3autogen.Ds3SpecParserImpl)2 CodeGenerator (com.spectralogic.ds3autogen.api.CodeGenerator)2