Search in sources :

Example 16 with GoTestCodeUtil

use of com.spectralogic.ds3autogen.go.utils.GoTestCodeUtil 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)

Example 17 with GoTestCodeUtil

use of com.spectralogic.ds3autogen.go.utils.GoTestCodeUtil in project ds3_autogen by SpectraLogic.

the class GoFunctionalTests method deleteObjects.

@Test
public void deleteObjects() throws IOException, TemplateModelException {
    // Test for request with object name list payload and optional void parameter
    final String requestName = "DeleteObjectsRequest";
    final FileUtils fileUtils = mock(FileUtils.class);
    final GoTestCodeUtil codeGenerator = new GoTestCodeUtil(fileUtils, requestName, "DeleteResult");
    codeGenerator.generateCode(fileUtils, "/input/deleteObjects.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: buildDeleteObjectsPayload(objectNames),"));
    assertTrue(returnsStream(requestName, requestCode));
    // verify with-constructor of void param type is generated correctly
    assertTrue(requestCode.contains("func (deleteObjectsRequest *DeleteObjectsRequest) WithRollBack() *DeleteObjectsRequest {"));
    assertFalse(requestCode.contains("deleteObjectsRequest.rollBack = rollBack"));
    // Verify Response file was generated
    final String responseCode = codeGenerator.getResponseCode();
    CODE_LOGGER.logFile(responseCode, FileTypeToLog.RESPONSE);
    assertTrue(hasContent(responseCode));
    assertTrue(responseCode.contains("DeleteResult DeleteResult"));
    assertFalse(responseCode.contains("`xml:\"DeleteResult\"`"));
    assertTrue(responseCode.contains("func NewDeleteObjectsResponse(webResponse networking.WebResponse) (*DeleteObjectsResponse, error) {"));
    assertTrue(responseCode.contains("expectedStatusCodes := []int { 200 }"));
    assertTrue(responseCode.contains("var body DeleteObjectsResponse"));
    assertTrue(responseCode.contains("if err := readResponseBody(webResponse, &body.DeleteResult); 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.POST);
    CODE_LOGGER.logFile(client, FileTypeToLog.CLIENT);
    assertTrue(hasContent(client));
    assertTrue(client.contains("func (client *Client) DeleteObjects(request *models.DeleteObjectsRequest) (*models.DeleteObjectsResponse, 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 18 with GoTestCodeUtil

use of com.spectralogic.ds3autogen.go.utils.GoTestCodeUtil in project ds3_autogen by SpectraLogic.

the class GoFunctionalTests method putAzureDataReplicationRule.

@Test
public void putAzureDataReplicationRule() throws IOException, TemplateModelException {
    // This tests generation of request with "type" required parameter keyword conflict
    final String requestName = "PutAzureDataReplicationRuleSpectraS3Request";
    final FileUtils fileUtils = mock(FileUtils.class);
    final GoTestCodeUtil codeGenerator = new GoTestCodeUtil(fileUtils, requestName, "AzureDataReplicationRule");
    codeGenerator.generateCode(fileUtils, "/input/putAzureDataReplicationRule.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("dataReplicationRuleType DataReplicationRuleType"));
    assertTrue(requestCode.contains("maxBlobPartSizeInBytes int64"));
    assertTrue(requestCode.contains("replicateDeletes bool"));
    assertTrue(requestCode.contains("targetId string"));
    // test constructor and
    assertTrue(requestCode.contains("func NewPutAzureDataReplicationRuleSpectraS3Request(dataPolicyId string, dataReplicationRuleType DataReplicationRuleType, targetId string) *PutAzureDataReplicationRuleSpectraS3Request {"));
    assertTrue(requestCode.contains("queryParams.Set(\"type\", dataReplicationRuleType.String())"));
    assertTrue(requestCode.contains("dataReplicationRuleType: dataReplicationRuleType,"));
    // test with-constructors
    assertTrue(requestCode.contains("func (putAzureDataReplicationRuleSpectraS3Request *PutAzureDataReplicationRuleSpectraS3Request) WithMaxBlobPartSizeInBytes(maxBlobPartSizeInBytes int64) *PutAzureDataReplicationRuleSpectraS3Request {"));
    assertTrue(requestCode.contains("func (putAzureDataReplicationRuleSpectraS3Request *PutAzureDataReplicationRuleSpectraS3Request) WithReplicateDeletes(replicateDeletes bool) *PutAzureDataReplicationRuleSpectraS3Request {"));
    // Verify Response file was generated
    final String responseCode = codeGenerator.getResponseCode();
    CODE_LOGGER.logFile(responseCode, FileTypeToLog.RESPONSE);
    assertTrue(hasContent(responseCode));
    assertTrue(responseCode.contains("AzureDataReplicationRule AzureDataReplicationRule"));
    assertFalse(responseCode.contains("`xml:\"AzureDataReplicationRule\"`"));
    assertTrue(responseCode.contains("func NewPutAzureDataReplicationRuleSpectraS3Response(webResponse networking.WebResponse) (*PutAzureDataReplicationRuleSpectraS3Response, error) {"));
    assertTrue(responseCode.contains("expectedStatusCodes := []int { 201 }"));
    assertTrue(responseCode.contains("if err := readResponseBody(webResponse, &body.AzureDataReplicationRule); 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.POST);
    CODE_LOGGER.logFile(client, FileTypeToLog.CLIENT);
    assertTrue(hasContent(client));
    assertTrue(client.contains("func (client *Client) PutAzureDataReplicationRuleSpectraS3(request *models.PutAzureDataReplicationRuleSpectraS3Request) (*models.PutAzureDataReplicationRuleSpectraS3Response, 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 19 with GoTestCodeUtil

use of com.spectralogic.ds3autogen.go.utils.GoTestCodeUtil in project ds3_autogen by SpectraLogic.

the class GoFunctionalTests method putObject.

@Test
public void putObject() throws IOException, TemplateModelException {
    // This tests correct generation of request with ReaderWithSizeDecorator payload
    final String requestName = "PutObjectRequest";
    final FileUtils fileUtils = mock(FileUtils.class);
    final GoTestCodeUtil codeGenerator = new GoTestCodeUtil(fileUtils, requestName);
    codeGenerator.generateCode(fileUtils, "/input/putObject.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\""));
    assertTrue(requestCode.contains("strings"));
    // test request struct
    assertTrue(requestCode.contains("bucketName string"));
    assertTrue(requestCode.contains("objectName string"));
    assertTrue(requestCode.contains("job string"));
    assertTrue(requestCode.contains("offset int64"));
    assertTrue(requestCode.contains("content networking.ReaderWithSizeDecorator"));
    assertTrue(requestCode.contains("checksum networking.Checksum"));
    assertTrue(requestCode.contains("headers *http.Header"));
    // test constructor
    assertTrue(requestCode.contains("func NewPutObjectRequest(bucketName string, objectName string, content networking.ReaderWithSizeDecorator) *PutObjectRequest {"));
    assertTrue(requestCode.contains("bucketName: bucketName,"));
    assertTrue(requestCode.contains("objectName: objectName,"));
    assertTrue(requestCode.contains("content: content,"));
    assertTrue(requestCode.contains("checksum: networking.NewNoneChecksum()"));
    assertTrue(requestCode.contains("headers: &http.Header{},"));
    // test path
    assertTrue(requestCode.contains("return \"/\" + putObjectRequest.bucketName + \"/\" + putObjectRequest.objectName"));
    // test content stream
    assertTrue(requestCode.contains("func (putObjectRequest *PutObjectRequest) GetContentStream() networking.ReaderWithSizeDecorator {"));
    assertTrue(requestCode.contains("return putObjectRequest.content"));
    // test checksum
    assertTrue(requestCode.contains("func (putObjectRequest *PutObjectRequest) WithChecksum(contentHash string, checksumType networking.ChecksumType) *PutObjectRequest {"));
    assertTrue(requestCode.contains("func (putObjectRequest *PutObjectRequest) GetChecksum() networking.Checksum {"));
    assertTrue(requestCode.contains("return putObjectRequest.checksum"));
    // test metadata
    assertTrue(requestCode.contains("const ( AMZ_META_HEADER = \"x-amz-meta-\" )"));
    assertTrue(requestCode.contains("func (putObjectRequest *PutObjectRequest) WithMetaData(key string, value string) *PutObjectRequest {"));
    assertTrue(requestCode.contains("func (putObjectRequest *PutObjectRequest) Header() *http.Header {"));
    assertTrue(requestCode.contains("return putObjectRequest.headers"));
    // Verify Response file was generated
    final String responseCode = codeGenerator.getResponseCode();
    CODE_LOGGER.logFile(responseCode, FileTypeToLog.RESPONSE);
    assertTrue(hasContent(responseCode));
    // 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) PutObject(request *models.PutObjectRequest) (*models.PutObjectResponse, 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)

Aggregations

FileUtils (com.spectralogic.ds3autogen.api.FileUtils)19 GoTestCodeUtil (com.spectralogic.ds3autogen.go.utils.GoTestCodeUtil)19 Test (org.junit.Test)19