Search in sources :

Example 6 with GoTestCodeUtil

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

the class GoFunctionalTests method requestWithResourceInPath.

@Test
public void requestWithResourceInPath() throws IOException, TemplateModelException {
    final String requestName = "DeleteBucketAclSpectraS3Request";
    final FileUtils fileUtils = mock(FileUtils.class);
    final GoTestCodeUtil codeGenerator = new GoTestCodeUtil(fileUtils, requestName);
    codeGenerator.generateCode(fileUtils, "/input/requestWithResourceInPath.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("func NewDeleteBucketAclSpectraS3Request(bucketAcl string) *DeleteBucketAclSpectraS3Request {"));
    assertTrue(requestCode.contains("return \"/_rest_/bucket_acl/\" + deleteBucketAclSpectraS3Request.bucketAcl"));
    assertFalse(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("func NewDeleteBucketAclSpectraS3Response(webResponse networking.WebResponse) (*DeleteBucketAclSpectraS3Response, error) {"));
    assertTrue(responseCode.contains("expectedStatusCodes := []int { 204 }"));
    assertTrue(responseCode.contains("return &DeleteBucketAclSpectraS3Response{}, 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.DELETE);
    CODE_LOGGER.logFile(client, FileTypeToLog.CLIENT);
    assertTrue(hasContent(client));
    assertTrue(client.contains("func (client *Client) DeleteBucketAclSpectraS3(request *models.DeleteBucketAclSpectraS3Request) (*models.DeleteBucketAclSpectraS3Response, 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 7 with GoTestCodeUtil

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

the class GoFunctionalTests method simpleRequestNoPayload.

@Test
public void simpleRequestNoPayload() throws IOException, TemplateModelException {
    final String requestName = "SimpleNoPayloadRequest";
    final FileUtils fileUtils = mock(FileUtils.class);
    final GoTestCodeUtil codeGenerator = new GoTestCodeUtil(fileUtils, requestName);
    codeGenerator.generateCode(fileUtils, "/input/simpleRequestNoPayload.xml");
    // Verify Request file was generated
    final String requestCode = codeGenerator.getRequestCode();
    CODE_LOGGER.logFile(requestCode, FileTypeToLog.REQUEST);
    assertTrue(hasContent(requestCode));
    // Verify Response file was generated
    final String responseCode = codeGenerator.getResponseCode();
    CODE_LOGGER.logFile(responseCode, FileTypeToLog.RESPONSE);
    assertTrue(hasContent(responseCode));
    assertTrue(responseCode.contains("func NewSimpleNoPayloadResponse(webResponse networking.WebResponse) (*SimpleNoPayloadResponse, error) {"));
    assertTrue(responseCode.contains("expectedStatusCodes := []int { 200 }"));
    assertTrue(responseCode.contains("return &SimpleNoPayloadResponse{}, 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) SimpleNoPayload(request *models.SimpleNoPayloadRequest) (*models.SimpleNoPayloadResponse, 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 8 with GoTestCodeUtil

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

the class GoFunctionalTests method getObject.

@Test
public void getObject() throws IOException, TemplateModelException {
    final String requestName = "GetObjectRequest";
    final FileUtils fileUtils = mock(FileUtils.class);
    final GoTestCodeUtil codeGenerator = new GoTestCodeUtil(fileUtils, requestName);
    codeGenerator.generateCode(fileUtils, "/input/getObject.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("\"fmt\""));
    assertTrue(requestCode.contains("\"net/url\""));
    assertTrue(requestCode.contains("\"net/http\""));
    assertTrue(requestCode.contains("\"ds3/networking\""));
    assertTrue(requestCode.contains("\"strconv\""));
    // test request struct
    assertTrue(requestCode.contains("rangeHeader *rangeHeader"));
    assertTrue(requestCode.contains("checksum networking.Checksum"));
    assertTrue(requestCode.contains("type rangeHeader struct {"));
    // test constructor and with-constructors
    assertTrue(requestCode.contains("func NewGetObjectRequest(bucketName string, objectName string) *GetObjectRequest {"));
    assertTrue(requestCode.contains("checksum: networking.NewNoneChecksum(),"));
    assertTrue(requestCode.contains(""));
    assertTrue(requestCode.contains("func (getObjectRequest *GetObjectRequest) WithRange(start, end int) *GetObjectRequest {"));
    assertTrue(requestCode.contains("func (getObjectRequest *GetObjectRequest) WithChecksum(contentHash string, checksumType networking.ChecksumType) *GetObjectRequest {"));
    assertTrue(requestCode.contains("func (getObjectRequest *GetObjectRequest) WithJob(job string) *GetObjectRequest {"));
    assertTrue(requestCode.contains("func (getObjectRequest *GetObjectRequest) WithOffset(offset int64) *GetObjectRequest {"));
    // test header and checksum functions
    assertTrue(requestCode.contains("func (getObjectRequest *GetObjectRequest) Header() *http.Header {"));
    assertTrue(requestCode.contains("return &http.Header{ \"Range\": []string{ rng } }"));
    assertTrue(requestCode.contains("func (getObjectRequest *GetObjectRequest) GetChecksum() networking.Checksum {"));
    assertTrue(requestCode.contains("return getObjectRequest.checksum"));
    assertTrue(requestCode.contains("func (GetObjectRequest) GetContentStream() networking.ReaderWithSizeDecorator {"));
    // Verify Response file was generated
    final String responseCode = codeGenerator.getResponseCode();
    CODE_LOGGER.logFile(responseCode, FileTypeToLog.RESPONSE);
    assertTrue(hasContent(responseCode));
    assertTrue(responseCode.contains("\"io\""));
    assertTrue(responseCode.contains("Content io.ReadCloser"));
    assertTrue(responseCode.contains("func NewGetObjectResponse(webResponse networking.WebResponse) (*GetObjectResponse, error) {"));
    assertTrue(responseCode.contains("expectedStatusCodes := []int { 200, 206 }"));
    assertTrue(responseCode.contains("return &GetObjectResponse{ Content: webResponse.Body() }, nil"));
    assertTrue(responseCode.contains("return &GetObjectResponse{}, 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) GetObject(request *models.GetObjectRequest) (*models.GetObjectResponse, 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 9 with GoTestCodeUtil

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

the class GoFunctionalTypeTests method jobNodeType.

@Test
public void jobNodeType() throws IOException, TemplateModelException {
    final String typeName = "JobNode";
    final FileUtils fileUtils = mock(FileUtils.class);
    final GoTestCodeUtil codeGenerator = new GoTestCodeUtil(fileUtils, requestName, typeName);
    codeGenerator.generateCode(fileUtils, "/input/jobNodeType.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("EndPoint *string `xml:\"EndPoint,attr\"`"));
    assertTrue(typeCode.contains("HttpPort *int `xml:\"HttpPort,attr\"`"));
    assertTrue(typeCode.contains("HttpsPort *int `xml:\"HttpsPort,attr\"`"));
    assertTrue(typeCode.contains("Id string `xml:\"Id,attr\"`"));
}
Also used : FileUtils(com.spectralogic.ds3autogen.api.FileUtils) GoTestCodeUtil(com.spectralogic.ds3autogen.go.utils.GoTestCodeUtil) Test(org.junit.Test)

Example 10 with GoTestCodeUtil

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

the class GoFunctionalTypeTests method jobList.

@Test
public void jobList() throws IOException, TemplateModelException {
    final String typeName = "JobList";
    final FileUtils fileUtils = mock(FileUtils.class);
    final GoTestCodeUtil codeGenerator = new GoTestCodeUtil(fileUtils, requestName, typeName);
    codeGenerator.generateCode(fileUtils, "/input/jobListType.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("Jobs []Job `xml:\"Job\"`"));
}
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