Search in sources :

Example 11 with GoTestCodeUtil

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

the class GoFunctionalTypeTests method jobType.

@Test
public void jobType() throws IOException, TemplateModelException {
    final String typeName = "Job";
    final FileUtils fileUtils = mock(FileUtils.class);
    final GoTestCodeUtil codeGenerator = new GoTestCodeUtil(fileUtils, requestName, typeName);
    codeGenerator.generateCode(fileUtils, "/input/jobType.xml");
    // Verify response payload type file was generated
    final String typeCode = codeGenerator.getTypeCode();
    CODE_LOGGER.logFile(typeCode, FileTypeToLog.MODEL);
    assertTrue(hasContent(typeCode));
    assertTrue(typeCode.contains("Aggregating bool `xml:\"Aggregating,attr\"`"));
    assertTrue(typeCode.contains("BucketName *string `xml:\"BucketName,attr\"`"));
    assertTrue(typeCode.contains("CachedSizeInBytes int64 `xml:\"CachedSizeInBytes,attr\"`"));
    assertTrue(typeCode.contains("ChunkClientProcessingOrderGuarantee JobChunkClientProcessingOrderGuarantee `xml:\"ChunkClientProcessingOrderGuarantee,attr\"`"));
    assertTrue(typeCode.contains("CompletedSizeInBytes int64 `xml:\"CompletedSizeInBytes,attr\"`"));
    assertTrue(typeCode.contains("EntirelyInCache bool `xml:\"EntirelyInCache,attr\"`"));
    assertTrue(typeCode.contains("JobId string `xml:\"JobId,attr\"`"));
    assertTrue(typeCode.contains("Naked bool `xml:\"Naked,attr\"`"));
    assertTrue(typeCode.contains("Name *string `xml:\"Name,attr\"`"));
    assertTrue(typeCode.contains("Nodes []JobNode `xml:\"Nodes>Node\"`"));
    assertTrue(typeCode.contains("OriginalSizeInBytes int64 `xml:\"OriginalSizeInBytes,attr\"`"));
    assertTrue(typeCode.contains("Priority Priority `xml:\"Priority,attr\"`"));
    assertTrue(typeCode.contains("RequestType JobRequestType `xml:\"RequestType,attr\"`"));
    assertTrue(typeCode.contains("StartDate string `xml:\"StartDate,attr\"`"));
    assertTrue(typeCode.contains("Status JobStatus `xml:\"Status,attr\"`"));
    assertTrue(typeCode.contains("UserId string `xml:\"UserId,attr\"`"));
    assertTrue(typeCode.contains("UserName *string `xml:\"UserName,attr\"`"));
}
Also used : FileUtils(com.spectralogic.ds3autogen.api.FileUtils) GoTestCodeUtil(com.spectralogic.ds3autogen.go.utils.GoTestCodeUtil) Test(org.junit.Test)

Example 12 with GoTestCodeUtil

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

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

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

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

Aggregations

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