use of com.thinkbiganalytics.spark.rest.model.TransformResponse in project kylo by Teradata.
the class AbstractTransformControllerTest method getTable.
/**
* Verify requesting a transformation status.
*/
@Test
public void getTable() throws Exception {
// Mock transform objects
TransformJob pendingJob = Mockito.mock(TransformJob.class);
Mockito.when(pendingJob.getGroupId()).thenReturn("PendingJob");
Mockito.when(pendingJob.progress()).thenReturn(0.5);
TransformJob successJob = Mockito.mock(TransformJob.class);
TransformResponse successResponse = new TransformResponse();
Mockito.when(successJob.get()).thenReturn(successResponse);
Mockito.when(successJob.isDone()).thenReturn(true);
TransformService transformService = Mockito.mock(TransformService.class);
Mockito.when(transformService.getTransformJob("PendingJob")).thenReturn(pendingJob);
Mockito.when(transformService.getTransformJob("SuccessJob")).thenReturn(successJob);
// Test with pending job
AbstractTransformController controller = new AbstractTransformController() {
};
controller.transformService = transformService;
Response response = controller.getTable("PendingJob");
Assert.assertEquals(Response.Status.OK, response.getStatusInfo());
TransformResponse transformResponse = (TransformResponse) response.getEntity();
Assert.assertEquals(0.5, transformResponse.getProgress(), 0.001);
Assert.assertEquals(TransformResponse.Status.PENDING, transformResponse.getStatus());
Assert.assertEquals("PendingJob", transformResponse.getTable());
// Test with success job
response = controller.getTable("SuccessJob");
Assert.assertEquals(successResponse, response.getEntity());
Assert.assertEquals(Response.Status.OK, response.getStatusInfo());
}
use of com.thinkbiganalytics.spark.rest.model.TransformResponse in project kylo by Teradata.
the class SparkShellTransformControllerTest method createWithMissingScript.
/**
* Verify response if missing script.
*/
@Test
public void createWithMissingScript() {
SparkShellTransformController controller = new SparkShellTransformController();
Response response = controller.create(new TransformRequest());
Assert.assertEquals(Response.Status.BAD_REQUEST, response.getStatusInfo());
TransformResponse entity = (TransformResponse) response.getEntity();
Assert.assertEquals("The request must include a script with the transformations to perform.", entity.getMessage());
Assert.assertEquals(TransformResponse.Status.ERROR, entity.getStatus());
}
use of com.thinkbiganalytics.spark.rest.model.TransformResponse in project kylo by Teradata.
the class SparkShellTransformControllerTest method createWithMissingParentTable.
/**
* Verify response if missing parent table.
*/
@Test
public void createWithMissingParentTable() {
// Create transform request
TransformRequest request = new TransformRequest();
request.setScript("parent");
TransformRequest.Parent parent = new TransformRequest.Parent();
parent.setScript("sqlContext.sql(\"SELECT * FROM invalid\")");
request.setParent(parent);
// Test missing parent table
SparkShellTransformController controller = new SparkShellTransformController();
Response response = controller.create(request);
Assert.assertEquals(Response.Status.BAD_REQUEST, response.getStatusInfo());
TransformResponse entity = (TransformResponse) response.getEntity();
Assert.assertEquals("The parent must include the table containing the results.", entity.getMessage());
Assert.assertEquals(TransformResponse.Status.ERROR, entity.getStatus());
}
use of com.thinkbiganalytics.spark.rest.model.TransformResponse in project kylo by Teradata.
the class SparkShellTransformControllerTest method create.
/**
* Verify requesting a Spark transformation.
*/
@Test
public void create() throws Exception {
// Mock transform objects
TransformRequest transformRequest = new TransformRequest();
transformRequest.setScript("sqlContext.sql(\"SELECT * FROM invalid\")");
TransformResponse transformResponse = new TransformResponse();
transformResponse.setProgress(0.0);
transformResponse.setStatus(TransformResponse.Status.PENDING);
transformResponse.setTable("results");
TransformService transformService = Mockito.mock(TransformService.class);
Mockito.when(transformService.execute(transformRequest)).thenReturn(transformResponse);
// Test transforming
SparkShellTransformController controller = new SparkShellTransformController();
controller.transformService = transformService;
Response response = controller.create(transformRequest);
Assert.assertEquals(Response.Status.OK, response.getStatusInfo());
Assert.assertEquals(transformResponse, response.getEntity());
}
use of com.thinkbiganalytics.spark.rest.model.TransformResponse in project kylo by Teradata.
the class SparkShellTransformControllerTest method createWithMissingParentScript.
/**
* Verify response if missing parent script.
*/
@Test
public void createWithMissingParentScript() {
// Create transform request
TransformRequest request = new TransformRequest();
request.setScript("parent");
request.setParent(new TransformRequest.Parent());
// Test missing parent script
SparkShellTransformController controller = new SparkShellTransformController();
Response response = controller.create(request);
Assert.assertEquals(Response.Status.BAD_REQUEST, response.getStatusInfo());
TransformResponse entity = (TransformResponse) response.getEntity();
Assert.assertEquals("The parent must include a script with the transformations performed.", entity.getMessage());
Assert.assertEquals(TransformResponse.Status.ERROR, entity.getStatus());
}
Aggregations