use of com.spectralogic.ds3autogen.api.FileUtils 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)"));
}
use of com.spectralogic.ds3autogen.api.FileUtils 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)"));
}
use of com.spectralogic.ds3autogen.api.FileUtils 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)"));
}
use of com.spectralogic.ds3autogen.api.FileUtils 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\"`"));
}
use of com.spectralogic.ds3autogen.api.FileUtils in project ds3_autogen by SpectraLogic.
the class NetCodeGenerator_Test method getJobChunksReadyForClientProcessingRequest_Test.
@Test
public void getJobChunksReadyForClientProcessingRequest_Test() throws IOException, TemplateModelException {
final String requestName = "GetJobChunksReadyForClientProcessingSpectraS3Request";
final FileUtils fileUtils = mock(FileUtils.class);
final TestGenerateCode codeGenerator = new TestGenerateCode(fileUtils, requestName, "./Ds3/Calls/", "MasterObjectList");
codeGenerator.generateCode(fileUtils, "/input/getJobChunksRequest.xml");
final String requestCode = codeGenerator.getRequestCode();
CODE_LOGGER.logFile(requestCode, FileTypeToLog.REQUEST);
assertTrue(TestHelper.extendsClass(requestName, "Ds3Request", requestCode));
assertTrue(TestHelper.hasProperty("Verb", "HttpVerb", requestCode));
assertTrue(TestHelper.hasProperty("Path", "string", requestCode));
assertTrue(TestHelper.hasRequiredParam("Job", "string", requestCode));
final ImmutableList<Arguments> constructorArgs = ImmutableList.of(new Arguments("Guid", "Job"));
assertTrue(TestHelper.hasConstructor(requestName, constructorArgs, requestCode));
assertTrue(TestHelper.hasConstructor(requestName, modifyType(constructorArgs, "Guid", "string"), requestCode));
//Generate Client code
final String commandName = requestName.replace("Request", "");
final String clientCode = codeGenerator.getClientCode();
CODE_LOGGER.logFile(clientCode, FileTypeToLog.CLIENT);
assertTrue(TestHelper.hasPayloadCommand(commandName, clientCode));
final String idsClientCode = codeGenerator.getIdsClientCode();
CODE_LOGGER.logFile(idsClientCode, FileTypeToLog.CLIENT);
assertTrue(TestHelper.hasIDsCommand(commandName, idsClientCode));
//Generate Responses
final String responseCode = codeGenerator.getResponseCode();
CODE_LOGGER.logFile(responseCode, FileTypeToLog.RESPONSE);
final String responsePayloadType = "Objects";
assertFalse(TestHelper.hasRequiredParam("ResponsePayload", responsePayloadType, responseCode));
//Generate Parser
final String parserCode = codeGenerator.getParserCode();
CODE_LOGGER.logFile(parserCode, FileTypeToLog.PARSER);
assertTrue(hasContent(parserCode));
assertFalse(parserHasResponseCode(200, parserCode));
assertTrue(parserHasPayload("MasterObjectList", "MasterObjectList", parserCode));
}
Aggregations