use of com.spectralogic.ds3autogen.go.utils.GoTestCodeUtil in project ds3_autogen by SpectraLogic.
the class GoFunctionalTypeTests method simpleEnumGeneration.
@Test
public void simpleEnumGeneration() throws IOException, TemplateModelException {
final String typeName = "DatabasePhysicalSpaceState";
final FileUtils fileUtils = mock(FileUtils.class);
final GoTestCodeUtil codeGenerator = new GoTestCodeUtil(fileUtils, requestName, typeName);
codeGenerator.generateCode(fileUtils, "/input/simpleEnum.xml");
// Verify response payload type file was generated
final String typeCode = codeGenerator.getTypeCode();
CODE_LOGGER.logFile(typeCode, FileTypeToLog.MODEL);
assertTrue(hasContent(typeCode));
// Test const definitions
assertTrue(typeCode.contains("DATABASE_PHYSICAL_SPACE_STATE_CRITICAL DatabasePhysicalSpaceState = 1 + iota"));
assertTrue(typeCode.contains("DATABASE_PHYSICAL_SPACE_STATE_LOW DatabasePhysicalSpaceState = 1 + iota"));
assertTrue(typeCode.contains("DATABASE_PHYSICAL_SPACE_STATE_NEAR_LOW DatabasePhysicalSpaceState = 1 + iota"));
assertTrue(typeCode.contains("DATABASE_PHYSICAL_SPACE_STATE_NORMAL DatabasePhysicalSpaceState = 1 + iota"));
// Test un-marshaling
assertTrue(typeCode.contains("case \"\": *databasePhysicalSpaceState = UNDEFINED"));
assertTrue(typeCode.contains("case \"CRITICAL\": *databasePhysicalSpaceState = DATABASE_PHYSICAL_SPACE_STATE_CRITICAL"));
assertTrue(typeCode.contains("case \"LOW\": *databasePhysicalSpaceState = DATABASE_PHYSICAL_SPACE_STATE_LOW"));
assertTrue(typeCode.contains("case \"NEAR_LOW\": *databasePhysicalSpaceState = DATABASE_PHYSICAL_SPACE_STATE_NEAR_LOW"));
assertTrue(typeCode.contains("case \"NORMAL\": *databasePhysicalSpaceState = DATABASE_PHYSICAL_SPACE_STATE_NORMAL"));
// Test conversion to string
assertTrue(typeCode.contains("case DATABASE_PHYSICAL_SPACE_STATE_CRITICAL: return \"CRITICAL\""));
assertTrue(typeCode.contains("case DATABASE_PHYSICAL_SPACE_STATE_LOW: return \"LOW\""));
assertTrue(typeCode.contains("case DATABASE_PHYSICAL_SPACE_STATE_NEAR_LOW: return \"NEAR_LOW\""));
assertTrue(typeCode.contains("case DATABASE_PHYSICAL_SPACE_STATE_NORMAL: return \"NORMAL\""));
}
use of com.spectralogic.ds3autogen.go.utils.GoTestCodeUtil in project ds3_autogen by SpectraLogic.
the class GoFunctionalTypeTests method simpleTypeGeneration.
@Test
public void simpleTypeGeneration() throws IOException, TemplateModelException {
final String typeName = "JobCompletedNotificationPayload";
final FileUtils fileUtils = mock(FileUtils.class);
final GoTestCodeUtil codeGenerator = new GoTestCodeUtil(fileUtils, requestName, typeName);
codeGenerator.generateCode(fileUtils, "/input/simpleType.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("CancelOccurred bool `xml:\"CancelOccurred\"`"));
assertTrue(typeCode.contains("JobId string `xml:\"JobId\"`"));
assertTrue(typeCode.contains("NotificationGenerationDate string `xml:\"NotificationGenerationDate\"`"));
assertTrue(typeCode.contains("ObjectsNotPersisted []BulkObject `xml:\"ObjectsNotPersisted>Object\"`"));
}
use of com.spectralogic.ds3autogen.go.utils.GoTestCodeUtil in project ds3_autogen by SpectraLogic.
the class GoFunctionalTests method completeMultipartUpload.
@Test
public void completeMultipartUpload() throws IOException, TemplateModelException {
// Test for request with CompleteMultipartUpload payload
final String requestName = "CompleteMultiPartUploadRequest";
final FileUtils fileUtils = mock(FileUtils.class);
final GoTestCodeUtil codeGenerator = new GoTestCodeUtil(fileUtils, requestName, "CompleteMultipartUploadResult");
codeGenerator.generateCode(fileUtils, "/input/completeMultipartUpload.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: buildPartsListStream(parts),"));
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("CompleteMultipartUploadResult CompleteMultipartUploadResult"));
assertFalse(responseCode.contains("`xml:\"CompleteMultipartUploadResult\"`"));
assertTrue(responseCode.contains("func NewCompleteMultiPartUploadResponse(webResponse networking.WebResponse) (*CompleteMultiPartUploadResponse, error) {"));
assertTrue(responseCode.contains("expectedStatusCodes := []int { 200 }"));
assertTrue(responseCode.contains("var body CompleteMultiPartUploadResponse"));
assertTrue(responseCode.contains("if err := readResponseBody(webResponse, &body.CompleteMultipartUploadResult); 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) CompleteMultiPartUpload(request *models.CompleteMultiPartUploadRequest) (*models.CompleteMultiPartUploadResponse, 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.go.utils.GoTestCodeUtil in project ds3_autogen by SpectraLogic.
the class GoFunctionalTests method verifyPhysicalPlacement.
@Test
public void verifyPhysicalPlacement() throws IOException, TemplateModelException {
// Test for request with payload of Ds3Object list
final String requestName = "VerifyPhysicalPlacementForObjectsSpectraS3Request";
final FileUtils fileUtils = mock(FileUtils.class);
final GoTestCodeUtil codeGenerator = new GoTestCodeUtil(fileUtils, requestName, "PhysicalPlacement");
codeGenerator.generateCode(fileUtils, "/input/verifyPhysicalPlacement.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: buildDs3ObjectListStream(objects),"));
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("PhysicalPlacement PhysicalPlacement"));
assertFalse(responseCode.contains("`xml:\"PhysicalPlacement\"`"));
assertTrue(responseCode.contains("func NewVerifyPhysicalPlacementForObjectsSpectraS3Response(webResponse networking.WebResponse) (*VerifyPhysicalPlacementForObjectsSpectraS3Response, error) {"));
assertTrue(responseCode.contains("expectedStatusCodes := []int { 200 }"));
assertTrue(responseCode.contains("var body VerifyPhysicalPlacementForObjectsSpectraS3Response"));
assertTrue(responseCode.contains("if err := readResponseBody(webResponse, &body.PhysicalPlacement); 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) VerifyPhysicalPlacementForObjectsSpectraS3(request *models.VerifyPhysicalPlacementForObjectsSpectraS3Request) (*models.VerifyPhysicalPlacementForObjectsSpectraS3Response, 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.go.utils.GoTestCodeUtil in project ds3_autogen by SpectraLogic.
the class GoFunctionalTests method deleteJobCreatedNotificationRegistration.
@Test
public void deleteJobCreatedNotificationRegistration() throws IOException, TemplateModelException {
// This tests correct generation of notificationId required parameter from resource
final String requestName = "DeleteJobCreatedNotificationRegistrationSpectraS3Request";
final FileUtils fileUtils = mock(FileUtils.class);
final GoTestCodeUtil codeGenerator = new GoTestCodeUtil(fileUtils, requestName);
codeGenerator.generateCode(fileUtils, "/input/deleteJobCreatedNotificationRegistration.xml");
// Verify Request file was generated
final String requestCode = codeGenerator.getRequestCode();
CODE_LOGGER.logFile(requestCode, FileTypeToLog.REQUEST);
assertTrue(hasContent(requestCode));
// test request imports
assertFalse(requestCode.contains("\"strconv\""));
assertTrue(requestCode.contains("\"net/url\""));
assertTrue(requestCode.contains("\"net/http\""));
assertTrue(requestCode.contains("\"ds3/networking\""));
// test request struct
assertTrue(requestCode.contains("notificationId string"));
assertTrue(requestCode.contains("queryParams *url.Values"));
// test constructor
assertTrue(requestCode.contains("func NewDeleteJobCreatedNotificationRegistrationSpectraS3Request(notificationId string) *DeleteJobCreatedNotificationRegistrationSpectraS3Request {"));
assertTrue(requestCode.contains("notificationId: notificationId,"));
// test path
assertTrue(requestCode.contains("return \"/_rest_/job_created_notification_registration/\" + deleteJobCreatedNotificationRegistrationSpectraS3Request.notificationId"));
// Verify Response file was generated
final String responseCode = codeGenerator.getResponseCode();
CODE_LOGGER.logFile(responseCode, FileTypeToLog.RESPONSE);
assertTrue(hasContent(responseCode));
assertTrue(responseCode.contains("func NewDeleteJobCreatedNotificationRegistrationSpectraS3Response(webResponse networking.WebResponse) (*DeleteJobCreatedNotificationRegistrationSpectraS3Response, error) {"));
assertTrue(responseCode.contains("expectedStatusCodes := []int { 204 }"));
assertTrue(responseCode.contains("return &DeleteJobCreatedNotificationRegistrationSpectraS3Response{}, 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) DeleteJobCreatedNotificationRegistrationSpectraS3(request *models.DeleteJobCreatedNotificationRegistrationSpectraS3Request) (*models.DeleteJobCreatedNotificationRegistrationSpectraS3Response, error) {"));
assertTrue(client.contains("networkRetryDecorator := networking.NewNetworkRetryDecorator(&(client.netLayer), client.clientPolicy.maxRetries)"));
assertTrue(client.contains("response, requestErr := networkRetryDecorator.Invoke(request)"));
}
Aggregations