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)"));
}
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)"));
}
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)"));
}
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)"));
}
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)"));
}
Aggregations