Skip to content

Commit

Permalink
fix integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
scottreisdorf committed Nov 27, 2018
1 parent e4b0348 commit 653aa3c
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@
import com.thinkbiganalytics.jobrepo.rest.controller.JobsRestController;
import com.thinkbiganalytics.jobrepo.rest.controller.ServiceLevelAssessmentsController;
import com.thinkbiganalytics.json.ObjectMapperSerializer;
import com.thinkbiganalytics.kylo.catalog.rest.controller.ConnectorController;
import com.thinkbiganalytics.kylo.catalog.rest.controller.DataSourceController;
import com.thinkbiganalytics.kylo.catalog.rest.model.Connector;
import com.thinkbiganalytics.kylo.catalog.rest.model.DataSource;
import com.thinkbiganalytics.metadata.api.feed.Feed;
import com.thinkbiganalytics.metadata.rest.model.data.Datasource;
import com.thinkbiganalytics.metadata.rest.model.data.JdbcDatasource;
Expand Down Expand Up @@ -285,7 +289,7 @@ protected FieldRuleProperty newFieldRuleProperty(String name, String objectPrope
}

protected void startClean() {
cleanup();
cleanup();
}

private void configureObjectMapper(ObjectMapper om) {
Expand Down Expand Up @@ -1256,6 +1260,31 @@ protected JdbcDatasource createDatasource(JdbcDatasource ds) {
return response.as(JdbcDatasource.class);
}

protected Connector[] listConnectors(){
Response response = given(ConnectorController.BASE)
.when()
.get();

response.then().statusCode(HTTP_OK);

return response.as(Connector[].class);

}


protected DataSource createDataSource(DataSource ds) {
LOG.info("Creating dataSource '{}'", ds.getTitle());

Response response = given(DataSourceController.BASE)
.body(ds)
.when()
.post();

response.then().statusCode(HTTP_OK);

return response.as(DataSource.class);
}

protected JdbcDatasource[] getDatasources() {
LOG.info("Getting datasources");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@
import org.springframework.beans.factory.annotation.Value;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

public class DataSourceIT extends IntegrationTestBase {
Expand All @@ -61,14 +63,22 @@ public class DataSourceIT extends IntegrationTestBase {
@Test
public void testFindAll() {
// Create a feed data source
final JdbcDatasource jdbcDatasourceRequest = new JdbcDatasource();
jdbcDatasourceRequest.setName("My Test SQL");
jdbcDatasourceRequest.setDatabaseConnectionUrl("jdbc:mysql://localhost:3306/kylo");
jdbcDatasourceRequest.setDatabaseDriverClassName("org.mariadb.jdbc.Driver");
jdbcDatasourceRequest.setDatabaseUser("root");
jdbcDatasourceRequest.setPassword("secret");
jdbcDatasourceRequest.setType("mysql");
final JdbcDatasource jdbcDatasource = createDatasource(jdbcDatasourceRequest);
final Connector[] connectors = listConnectors();

Connector jdbcConnector = Arrays.asList(connectors).stream().filter(c -> c.getPluginId().equalsIgnoreCase("jdbc")).findFirst().orElse(null);

DataSource ds = new DataSource();
ds.setConnector(jdbcConnector);
ds.setTitle("MySql Test");
DefaultDataSetTemplate dsTemplate = new DefaultDataSetTemplate();
Map<String, String> options = new HashMap<>();
options.put("driver", "org.mariadb.jdbc.Driver");
options.put("user", "root");
options.put("password", "secret");
options.put("url", "jdbc:mysql://localhost:3306/kylo");
dsTemplate.setOptions(options);
ds.setTemplate(dsTemplate);
final DataSource jdbcDatasource = createDataSource(ds);

// Find all data sources
final SearchResult<DataSource> searchResult = given(DataSourceController.BASE)
Expand All @@ -86,7 +96,7 @@ public boolean matches(final Object item) {
@Override
public boolean matches(final Object item) {
final DataSource dataSource = (item instanceof DataSource) ? (DataSource) item : null;
return (dataSource != null && jdbcDatasource.getId().equals(dataSource.getId()) && jdbcDatasource.getName().equals(dataSource.getTitle()));
return (dataSource != null && jdbcDatasource.getId().equals(dataSource.getId()) && jdbcDatasource.getTitle().equals(dataSource.getTitle()));
}
};
Assert.assertThat(searchResult.getData(), CoreMatchers.hasItem(isHive));
Expand Down

0 comments on commit 653aa3c

Please sign in to comment.