http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/30711973/webapp/src/test/java/org/apache/hadoop/metadata/web/resources/MetadataDiscoveryJerseyResourceIT.java ---------------------------------------------------------------------- diff --git a/webapp/src/test/java/org/apache/hadoop/metadata/web/resources/MetadataDiscoveryJerseyResourceIT.java b/webapp/src/test/java/org/apache/hadoop/metadata/web/resources/MetadataDiscoveryJerseyResourceIT.java deleted file mode 100755 index 0682295..0000000 --- a/webapp/src/test/java/org/apache/hadoop/metadata/web/resources/MetadataDiscoveryJerseyResourceIT.java +++ /dev/null @@ -1,223 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.hadoop.metadata.web.resources; - -import com.google.common.collect.ImmutableList; -import com.sun.jersey.api.client.ClientResponse; -import com.sun.jersey.api.client.WebResource; -import org.apache.hadoop.metadata.MetadataServiceClient; -import org.apache.hadoop.metadata.typesystem.Referenceable; -import org.apache.hadoop.metadata.typesystem.Struct; -import org.apache.hadoop.metadata.typesystem.TypesDef; -import org.apache.hadoop.metadata.typesystem.persistence.Id; -import org.apache.hadoop.metadata.typesystem.types.ClassType; -import org.apache.hadoop.metadata.typesystem.types.DataTypes; -import org.apache.hadoop.metadata.typesystem.types.EnumTypeDefinition; -import org.apache.hadoop.metadata.typesystem.types.HierarchicalTypeDefinition; -import org.apache.hadoop.metadata.typesystem.types.StructTypeDefinition; -import org.apache.hadoop.metadata.typesystem.types.TraitType; -import org.apache.hadoop.metadata.typesystem.types.TypeUtils; -import org.apache.hadoop.metadata.typesystem.types.utils.TypesUtil; -import org.apache.hadoop.metadata.web.util.Servlets; -import org.codehaus.jettison.json.JSONArray; -import org.codehaus.jettison.json.JSONObject; -import org.testng.Assert; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import javax.ws.rs.HttpMethod; -import javax.ws.rs.core.Response; -import java.util.List; - -/** - * Search Integration Tests. - */ -public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT { - - @BeforeClass - public void setUp() throws Exception { - super.setUp(); - - createTypes(); - createInstance(); - } - - @Test - public void testSearchByDSL() throws Exception { - String dslQuery = "from dsl_test_type"; - WebResource resource = service - .path("api/metadata/discovery/search/dsl") - .queryParam("query", dslQuery); - - ClientResponse clientResponse = resource - .accept(Servlets.JSON_MEDIA_TYPE) - .type(Servlets.JSON_MEDIA_TYPE) - .method(HttpMethod.GET, ClientResponse.class); - Assert.assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode()); - - String responseAsString = clientResponse.getEntity(String.class); - Assert.assertNotNull(responseAsString); - - JSONObject response = new JSONObject(responseAsString); - Assert.assertNotNull(response.get(MetadataServiceClient.REQUEST_ID)); - - Assert.assertEquals(response.getString("query"), dslQuery); - Assert.assertEquals(response.getString("queryType"), "dsl"); - - JSONObject results = response.getJSONObject(MetadataServiceClient.RESULTS); - Assert.assertNotNull(results); - - JSONArray rows = results.getJSONArray(MetadataServiceClient.ROWS); - Assert.assertEquals(rows.length(), 1); - - int numRows = response.getInt(MetadataServiceClient.COUNT); - Assert.assertEquals(numRows, 1); - - } - - @Test - public void testSearchByDSLForUnknownType() throws Exception { - String dslQuery = "from blah"; - WebResource resource = service - .path("api/metadata/discovery/search/dsl") - .queryParam("query", dslQuery); - - ClientResponse clientResponse = resource - .accept(Servlets.JSON_MEDIA_TYPE) - .type(Servlets.JSON_MEDIA_TYPE) - .method(HttpMethod.GET, ClientResponse.class); - Assert.assertEquals(clientResponse.getStatus(), - Response.Status.BAD_REQUEST.getStatusCode()); - } - - @Test - public void testSearchUsingGremlin() throws Exception { - String query = "g.V.has('type', 'dsl_test_type').toList()"; - WebResource resource = service - .path("api/metadata/discovery/search") - .queryParam("query", query); - - ClientResponse clientResponse = resource - .accept(Servlets.JSON_MEDIA_TYPE) - .type(Servlets.JSON_MEDIA_TYPE) - .method(HttpMethod.GET, ClientResponse.class); - Assert.assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode()); - - String responseAsString = clientResponse.getEntity(String.class); - Assert.assertNotNull(responseAsString); - - JSONObject response = new JSONObject(responseAsString); - Assert.assertNotNull(response.get(MetadataServiceClient.REQUEST_ID)); - - Assert.assertEquals(response.getString("query"), query); - Assert.assertEquals(response.getString("queryType"), "gremlin"); - } - - @Test - public void testSearchUsingDSL() throws Exception { - String query = "from dsl_test_type"; - WebResource resource = service - .path("api/metadata/discovery/search") - .queryParam("query", query); - - ClientResponse clientResponse = resource - .accept(Servlets.JSON_MEDIA_TYPE) - .type(Servlets.JSON_MEDIA_TYPE) - .method(HttpMethod.GET, ClientResponse.class); - Assert.assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode()); - - String responseAsString = clientResponse.getEntity(String.class); - Assert.assertNotNull(responseAsString); - - JSONObject response = new JSONObject(responseAsString); - Assert.assertNotNull(response.get(MetadataServiceClient.REQUEST_ID)); - - Assert.assertEquals(response.getString("query"), query); - Assert.assertEquals(response.getString("queryType"), "dsl"); - } - - @Test(enabled = false) - public void testSearchUsingFullText() throws Exception { - String query = "foundation_etl"; - JSONObject response = serviceClient.searchByFullText(query); - Assert.assertNotNull(response.get(MetadataServiceClient.REQUEST_ID)); - - Assert.assertEquals(response.getString("query"), query); - Assert.assertEquals(response.getString("queryType"), "full-text"); - - JSONArray results = response.getJSONArray(MetadataServiceClient.RESULTS); - Assert.assertEquals(results.length(), 1); - - JSONObject row = results.getJSONObject(0); - Assert.assertNotNull(row.get("guid")); - Assert.assertEquals(row.getString("typeName"), "dsl_test_type"); - Assert.assertNotNull(row.get("score")); - - int numRows = response.getInt(MetadataServiceClient.COUNT); - Assert.assertEquals(numRows, 1); - } - - private void createTypes() throws Exception { - HierarchicalTypeDefinition<ClassType> dslTestTypeDefinition = - TypesUtil.createClassTypeDef("dsl_test_type", - ImmutableList.<String>of(), - TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE), - TypesUtil.createRequiredAttrDef("description", DataTypes.STRING_TYPE)); - - HierarchicalTypeDefinition<TraitType> classificationTraitDefinition = - TypesUtil.createTraitTypeDef("Classification", - ImmutableList.<String>of(), - TypesUtil.createRequiredAttrDef("tag", DataTypes.STRING_TYPE)); - HierarchicalTypeDefinition<TraitType> piiTrait = - TypesUtil.createTraitTypeDef("PII_TYPE", ImmutableList.<String>of()); - HierarchicalTypeDefinition<TraitType> phiTrait = - TypesUtil.createTraitTypeDef("PHI", ImmutableList.<String>of()); - HierarchicalTypeDefinition<TraitType> pciTrait = - TypesUtil.createTraitTypeDef("PCI", ImmutableList.<String>of()); - HierarchicalTypeDefinition<TraitType> soxTrait = - TypesUtil.createTraitTypeDef("SOX", ImmutableList.<String>of()); - HierarchicalTypeDefinition<TraitType> secTrait = - TypesUtil.createTraitTypeDef("SEC", ImmutableList.<String>of()); - HierarchicalTypeDefinition<TraitType> financeTrait = - TypesUtil.createTraitTypeDef("Finance", ImmutableList.<String>of()); - - TypesDef typesDef = TypeUtils.getTypesDef( - ImmutableList.<EnumTypeDefinition>of(), - ImmutableList.<StructTypeDefinition>of(), - ImmutableList.of(classificationTraitDefinition, piiTrait, phiTrait, pciTrait, - soxTrait, secTrait, financeTrait), - ImmutableList.of(dslTestTypeDefinition)); - createType(typesDef); - } - - private Id createInstance() throws Exception { - Referenceable entityInstance = new Referenceable("dsl_test_type", - "Classification", "PII_TYPE", "PHI", "PCI", "SOX", "SEC", "Finance"); - entityInstance.set("name", "foo name"); - entityInstance.set("description", "bar description"); - - Struct traitInstance = (Struct) entityInstance.getTrait("Classification"); - traitInstance.set("tag", "foundation_etl"); - - List<String> traits = entityInstance.getTraits(); - Assert.assertEquals(traits.size(), 7); - - return createInstance(entityInstance); - } -}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/30711973/webapp/src/test/java/org/apache/hadoop/metadata/web/resources/RexsterGraphJerseyResourceIT.java ---------------------------------------------------------------------- diff --git a/webapp/src/test/java/org/apache/hadoop/metadata/web/resources/RexsterGraphJerseyResourceIT.java b/webapp/src/test/java/org/apache/hadoop/metadata/web/resources/RexsterGraphJerseyResourceIT.java deleted file mode 100755 index 7ebd7e1..0000000 --- a/webapp/src/test/java/org/apache/hadoop/metadata/web/resources/RexsterGraphJerseyResourceIT.java +++ /dev/null @@ -1,86 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.hadoop.metadata.web.resources; - -import com.sun.jersey.api.client.ClientResponse; -import com.sun.jersey.api.client.WebResource; -import org.apache.hadoop.metadata.web.util.Servlets; -import org.testng.Assert; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import javax.ws.rs.HttpMethod; -import javax.ws.rs.core.Response; - -/** - * Integration tests for Rexster Graph Jersey Resource. - */ -@Test -public class RexsterGraphJerseyResourceIT extends BaseResourceIT { - - @BeforeClass - @Override - public void setUp() throws Exception { - super.setUp(); - } - - @Test(enabled = false) - public void testGetVertex() throws Exception { - // todo: add a vertex before fetching it - - WebResource resource = service - .path("api/metadata/graph/vertices") - .path("0"); - - ClientResponse clientResponse = resource - .accept(Servlets.JSON_MEDIA_TYPE) - .type(Servlets.JSON_MEDIA_TYPE) - .method(HttpMethod.GET, ClientResponse.class); - Assert.assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode()); - String response = clientResponse.getEntity(String.class); - Assert.assertNotNull(response); - } - - public void testGetVertexWithInvalidId() throws Exception { - WebResource resource = service - .path("api/metadata/graph/vertices/blah"); - - ClientResponse clientResponse = resource - .accept(Servlets.JSON_MEDIA_TYPE) - .type(Servlets.JSON_MEDIA_TYPE) - .method(HttpMethod.GET, ClientResponse.class); - Assert.assertEquals(clientResponse.getStatus(), Response.Status.NOT_FOUND.getStatusCode()); - } - - public void testGetVertexProperties() throws Exception { - - } - - public void testGetVertices() throws Exception { - - } - - public void testGetVertexEdges() throws Exception { - - } - - public void testGetEdge() throws Exception { - - } -} http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/30711973/webapp/src/test/java/org/apache/hadoop/metadata/web/resources/TypesJerseyResourceIT.java ---------------------------------------------------------------------- diff --git a/webapp/src/test/java/org/apache/hadoop/metadata/web/resources/TypesJerseyResourceIT.java b/webapp/src/test/java/org/apache/hadoop/metadata/web/resources/TypesJerseyResourceIT.java deleted file mode 100755 index 0d9e710..0000000 --- a/webapp/src/test/java/org/apache/hadoop/metadata/web/resources/TypesJerseyResourceIT.java +++ /dev/null @@ -1,235 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.hadoop.metadata.web.resources; - -import com.google.common.collect.ImmutableList; -import com.sun.jersey.api.client.ClientResponse; -import com.sun.jersey.api.client.WebResource; -import org.apache.hadoop.metadata.MetadataServiceClient; -import org.apache.hadoop.metadata.typesystem.TypesDef; -import org.apache.hadoop.metadata.typesystem.json.TypesSerialization; -import org.apache.hadoop.metadata.typesystem.json.TypesSerialization$; -import org.apache.hadoop.metadata.typesystem.types.AttributeDefinition; -import org.apache.hadoop.metadata.typesystem.types.ClassType; -import org.apache.hadoop.metadata.typesystem.types.DataTypes; -import org.apache.hadoop.metadata.typesystem.types.HierarchicalTypeDefinition; -import org.apache.hadoop.metadata.typesystem.types.Multiplicity; -import org.apache.hadoop.metadata.typesystem.types.TraitType; -import org.apache.hadoop.metadata.typesystem.types.utils.TypesUtil; -import org.apache.hadoop.metadata.web.util.Servlets; -import org.codehaus.jettison.json.JSONArray; -import org.codehaus.jettison.json.JSONObject; -import org.testng.Assert; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import javax.ws.rs.HttpMethod; -import javax.ws.rs.core.Response; -import java.util.ArrayList; -import java.util.List; - -/** - * Integration test for types jersey resource. - */ -public class TypesJerseyResourceIT extends BaseResourceIT { - - private List<HierarchicalTypeDefinition> typeDefinitions; - - @BeforeClass - public void setUp() throws Exception { - super.setUp(); - - typeDefinitions = createHiveTypes(); - } - - @AfterClass - public void tearDown() throws Exception { - typeDefinitions.clear(); - } - - @Test - public void testSubmit() throws Exception { - for (HierarchicalTypeDefinition typeDefinition : typeDefinitions) { - String typesAsJSON = TypesSerialization.toJson(typeDefinition); - System.out.println("typesAsJSON = " + typesAsJSON); - - WebResource resource = service - .path("api/metadata/types"); - - ClientResponse clientResponse = resource - .accept(Servlets.JSON_MEDIA_TYPE) - .type(Servlets.JSON_MEDIA_TYPE) - .method(HttpMethod.POST, ClientResponse.class, typesAsJSON); - Assert.assertEquals(clientResponse.getStatus(), Response.Status.CREATED.getStatusCode()); - - String responseAsString = clientResponse.getEntity(String.class); - Assert.assertNotNull(responseAsString); - - JSONObject response = new JSONObject(responseAsString); - JSONArray typesAdded = response.getJSONArray(MetadataServiceClient.TYPES); - Assert.assertEquals(typesAdded.length(), 1); - Assert.assertEquals(typesAdded.getJSONObject(0).getString("name"), typeDefinition.typeName); - Assert.assertNotNull(response.get(MetadataServiceClient.REQUEST_ID)); - } - } - - @Test(dependsOnMethods = "testSubmit") - public void testGetDefinition() throws Exception { - for (HierarchicalTypeDefinition typeDefinition : typeDefinitions) { - System.out.println("typeName = " + typeDefinition.typeName); - - WebResource resource = service - .path("api/metadata/types") - .path(typeDefinition.typeName); - - ClientResponse clientResponse = resource - .accept(Servlets.JSON_MEDIA_TYPE) - .type(Servlets.JSON_MEDIA_TYPE) - .method(HttpMethod.GET, ClientResponse.class); - Assert.assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode()); - - String responseAsString = clientResponse.getEntity(String.class); - Assert.assertNotNull(responseAsString); - JSONObject response = new JSONObject(responseAsString); - Assert.assertNotNull(response.get(MetadataServiceClient.DEFINITION)); - Assert.assertNotNull(response.get(MetadataServiceClient.REQUEST_ID)); - - String typesJson = response.getString(MetadataServiceClient.DEFINITION); - final TypesDef typesDef = TypesSerialization.fromJson(typesJson); - List<HierarchicalTypeDefinition<ClassType>> hierarchicalTypeDefinitions = typesDef.classTypesAsJavaList(); - for(HierarchicalTypeDefinition<ClassType> classType : hierarchicalTypeDefinitions) { - for(AttributeDefinition attrDef : classType.attributeDefinitions) { - if("name".equals(attrDef.name)) { - Assert.assertEquals(attrDef.isIndexable, true); - Assert.assertEquals(attrDef.isUnique, true); - } - } - } - } - } - - @Test - public void testGetDefinitionForNonexistentType() throws Exception { - WebResource resource = service - .path("api/metadata/types") - .path("blah"); - - ClientResponse clientResponse = resource - .accept(Servlets.JSON_MEDIA_TYPE) - .type(Servlets.JSON_MEDIA_TYPE) - .method(HttpMethod.GET, ClientResponse.class); - Assert.assertEquals(clientResponse.getStatus(), Response.Status.NOT_FOUND.getStatusCode()); - } - - @Test(dependsOnMethods = "testSubmit") - public void testGetTypeNames() throws Exception { - WebResource resource = service - .path("api/metadata/types"); - - ClientResponse clientResponse = resource - .accept(Servlets.JSON_MEDIA_TYPE) - .type(Servlets.JSON_MEDIA_TYPE) - .method(HttpMethod.GET, ClientResponse.class); - Assert.assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode()); - - String responseAsString = clientResponse.getEntity(String.class); - Assert.assertNotNull(responseAsString); - - JSONObject response = new JSONObject(responseAsString); - Assert.assertNotNull(response.get(MetadataServiceClient.REQUEST_ID)); - - final JSONArray list = response.getJSONArray(MetadataServiceClient.RESULTS); - Assert.assertNotNull(list); - } - - @Test - public void testGetTraitNames() throws Exception { - String[] traitsAdded = addTraits(); - - WebResource resource = service - .path("api/metadata/types"); - - ClientResponse clientResponse = resource - .queryParam("type", DataTypes.TypeCategory.TRAIT.name()) - .accept(Servlets.JSON_MEDIA_TYPE) - .type(Servlets.JSON_MEDIA_TYPE) - .method(HttpMethod.GET, ClientResponse.class); - Assert.assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode()); - - String responseAsString = clientResponse.getEntity(String.class); - Assert.assertNotNull(responseAsString); - - JSONObject response = new JSONObject(responseAsString); - Assert.assertNotNull(response.get(MetadataServiceClient.REQUEST_ID)); - - final JSONArray list = response.getJSONArray(MetadataServiceClient.RESULTS); - Assert.assertNotNull(list); - Assert.assertTrue(list.length() >= traitsAdded.length); - } - - private String[] addTraits() throws Exception { - String[] traitNames = { - "class_trait", - "secure_trait", - "pii_trait", - "ssn_trait", - "salary_trait", - "sox_trait", - }; - - for (String traitName : traitNames) { - HierarchicalTypeDefinition<TraitType> traitTypeDef = - TypesUtil.createTraitTypeDef(traitName, ImmutableList.<String>of()); - String json = TypesSerialization$.MODULE$.toJson(traitTypeDef, true); - createType(json); - } - - return traitNames; - } - - private List<HierarchicalTypeDefinition> createHiveTypes() throws Exception { - ArrayList<HierarchicalTypeDefinition> typeDefinitions = new ArrayList<>(); - - HierarchicalTypeDefinition<ClassType> databaseTypeDefinition = - TypesUtil.createClassTypeDef("database", - ImmutableList.<String>of(), - TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE), - TypesUtil.createRequiredAttrDef("description", DataTypes.STRING_TYPE)); - typeDefinitions.add(databaseTypeDefinition); - - HierarchicalTypeDefinition<ClassType> tableTypeDefinition = TypesUtil.createClassTypeDef( - "table", - ImmutableList.<String>of(), - TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE), - TypesUtil.createRequiredAttrDef("description", DataTypes.STRING_TYPE), - TypesUtil.createRequiredAttrDef("type", DataTypes.STRING_TYPE), - new AttributeDefinition("database", - "database", Multiplicity.REQUIRED, false, "database")); - typeDefinitions.add(tableTypeDefinition); - - HierarchicalTypeDefinition<TraitType> fetlTypeDefinition = TypesUtil.createTraitTypeDef( - "fetl", - ImmutableList.<String>of(), - TypesUtil.createRequiredAttrDef("level", DataTypes.INT_TYPE)); - typeDefinitions.add(fetlTypeDefinition); - - return typeDefinitions; - } -} http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/30711973/webapp/src/test/java/org/apache/hadoop/metadata/web/service/SecureEmbeddedServerIT.java ---------------------------------------------------------------------- diff --git a/webapp/src/test/java/org/apache/hadoop/metadata/web/service/SecureEmbeddedServerIT.java b/webapp/src/test/java/org/apache/hadoop/metadata/web/service/SecureEmbeddedServerIT.java deleted file mode 100644 index 3c5b229..0000000 --- a/webapp/src/test/java/org/apache/hadoop/metadata/web/service/SecureEmbeddedServerIT.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.hadoop.metadata.web.service; - -import org.apache.commons.configuration.PropertiesConfiguration; -import org.testng.Assert; -import org.testng.annotations.Test; - -import java.net.HttpURLConnection; -import java.net.URL; - -import static org.apache.hadoop.metadata.security.SecurityProperties.*; - -public class SecureEmbeddedServerIT extends SecureEmbeddedServerITBase{ - @Test - public void testServerConfiguredUsingCredentialProvider() throws Exception { - // setup the configuration - final PropertiesConfiguration configuration = new PropertiesConfiguration(); - configuration.setProperty(CERT_STORES_CREDENTIAL_PROVIDER_PATH, providerUrl); - // setup the credential provider - setupCredentials(); - - SecureEmbeddedServer secureEmbeddedServer = null; - try { - String appPath = System.getProperty("user.dir") + getWarPath(); - secureEmbeddedServer = new SecureEmbeddedServer(21443, appPath) { - @Override - protected PropertiesConfiguration getConfiguration() { - return configuration; - } - }; - secureEmbeddedServer.server.start(); - - URL url = new URL("https://localhost:21443/"); - HttpURLConnection connection = (HttpURLConnection)url.openConnection(); - connection.setRequestMethod("GET"); - connection.connect(); - - // test to see whether server is up and root page can be served - Assert.assertEquals(connection.getResponseCode(), 200); - } finally { - secureEmbeddedServer.server.stop(); - } - - } -} http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/30711973/webapp/src/test/java/org/apache/hadoop/metadata/web/service/SecureEmbeddedServerITBase.java ---------------------------------------------------------------------- diff --git a/webapp/src/test/java/org/apache/hadoop/metadata/web/service/SecureEmbeddedServerITBase.java b/webapp/src/test/java/org/apache/hadoop/metadata/web/service/SecureEmbeddedServerITBase.java deleted file mode 100755 index 64358b8..0000000 --- a/webapp/src/test/java/org/apache/hadoop/metadata/web/service/SecureEmbeddedServerITBase.java +++ /dev/null @@ -1,221 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.hadoop.metadata.web.service; - -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.WebResource; -import com.sun.jersey.api.client.config.DefaultClientConfig; -import org.apache.commons.configuration.PropertiesConfiguration; -import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.fs.Path; -import org.apache.hadoop.metadata.web.resources.*; -import org.apache.hadoop.security.alias.CredentialProvider; -import org.apache.hadoop.security.alias.CredentialProviderFactory; -import org.apache.hadoop.security.alias.JavaKeyStoreProvider; -import org.mortbay.jetty.webapp.WebAppContext; -import org.testng.Assert; -import org.testng.TestListenerAdapter; -import org.testng.TestNG; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import javax.ws.rs.core.UriBuilder; -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.net.HttpURLConnection; -import java.net.URL; -import java.nio.file.Files; -import java.util.List; - -import static org.apache.hadoop.metadata.security.SecurityProperties.*; - -/** - * - */ -public class SecureEmbeddedServerITBase { - - - private SecureEmbeddedServer secureEmbeddedServer; - protected String providerUrl; - private Path jksPath; - protected WebResource service; - - static { - //for localhost testing only - javax.net.ssl.HttpsURLConnection.setDefaultHostnameVerifier( - new javax.net.ssl.HostnameVerifier(){ - - public boolean verify(String hostname, - javax.net.ssl.SSLSession sslSession) { - if (hostname.equals("localhost")) { - return true; - } - return false; - } - }); - System.setProperty("javax.net.ssl.trustStore", DEFAULT_KEYSTORE_FILE_LOCATION); - System.setProperty("javax.net.ssl.trustStorePassword", "keypass"); - System.setProperty("javax.net.ssl.trustStoreType", "JKS"); - } - - @BeforeClass - public void setupServerURI () throws Exception { - BaseResourceIT.baseUrl = "https://localhost:21443"; - } - - @AfterClass - public void resetServerURI() throws Exception { - BaseResourceIT.baseUrl = "http://localhost:21000"; - } - - @BeforeMethod - public void setup() throws Exception { - jksPath = new Path(Files.createTempDirectory("tempproviders").toString(), "test.jks"); - providerUrl = JavaKeyStoreProvider.SCHEME_NAME + "://file" + jksPath.toUri(); - - String baseUrl = "https://localhost:21443/"; - - DefaultClientConfig config = new DefaultClientConfig(); - Client client = Client.create(config); - client.resource(UriBuilder.fromUri(baseUrl).build()); - - service = client.resource(UriBuilder.fromUri(baseUrl).build()); - } - - @Test - public void testNoConfiguredCredentialProvider() throws Exception { - - try { - secureEmbeddedServer = new SecureEmbeddedServer(21443, "webapp/target/metadata-governance"); - WebAppContext webapp = new WebAppContext(); - webapp.setContextPath("/"); - webapp.setWar(System.getProperty("user.dir") + getWarPath()); - secureEmbeddedServer.server.setHandler(webapp); - - secureEmbeddedServer.server.start(); - - Assert.fail("Should have thrown an exception"); - } catch (IOException e) { - Assert.assertEquals("No credential provider path configured for storage of certificate store passwords", e.getMessage()); - } finally { - secureEmbeddedServer.server.stop(); - } - } - - @Test - public void testMissingEntriesInCredentialProvider() throws Exception { - // setup the configuration - final PropertiesConfiguration configuration = new PropertiesConfiguration(); - configuration.setProperty(CERT_STORES_CREDENTIAL_PROVIDER_PATH, providerUrl); - - try { - secureEmbeddedServer = new SecureEmbeddedServer(21443, "webapp/target/metadata-governance") { - @Override - protected PropertiesConfiguration getConfiguration() { - return configuration; - } - }; - Assert.fail("No entries should generate an exception"); - } catch (IOException e) { - Assert.assertTrue(e.getMessage().startsWith("No credential entry found for")); - } finally { - secureEmbeddedServer.server.stop(); - } - - } - - /** - * Runs the existing webapp test cases, this time against the initiated secure server instance. - * @throws Exception - */ - @Test - public void runOtherSuitesAgainstSecureServer() throws Exception { - final PropertiesConfiguration configuration = new PropertiesConfiguration(); - configuration.setProperty(CERT_STORES_CREDENTIAL_PROVIDER_PATH, providerUrl); - // setup the credential provider - setupCredentials(); - - try { - secureEmbeddedServer = new SecureEmbeddedServer(21443, "webapp/target/metadata-governance") { - @Override - protected PropertiesConfiguration getConfiguration() { - return configuration; - } - }; - WebAppContext webapp = new WebAppContext(); - webapp.setContextPath("/"); - webapp.setWar(System.getProperty("user.dir") + getWarPath()); - secureEmbeddedServer.server.setHandler(webapp); - - secureEmbeddedServer.server.start(); - - TestListenerAdapter tla = new TestListenerAdapter(); - TestNG testng = new TestNG(); - testng.setTestClasses(new Class[] { AdminJerseyResourceIT.class, EntityJerseyResourceIT.class, - MetadataDiscoveryJerseyResourceIT.class, RexsterGraphJerseyResourceIT.class, TypesJerseyResourceIT.class}); - testng.addListener(tla); - testng.run(); - - } finally { - secureEmbeddedServer.server.stop(); - } - - } - - protected String getWarPath() { - return String.format("/target/metadata-webapp-%s", - System.getProperty("project.version", "0.1-incubating-SNAPSHOT")); - } - - protected void setupCredentials() throws Exception { - Configuration conf = new Configuration(false); - - File file = new File(jksPath.toUri().getPath()); - file.delete(); - conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, providerUrl); - - CredentialProvider provider = - CredentialProviderFactory.getProviders(conf).get(0); - - // create new aliases - try { - - char[] storepass = {'k', 'e', 'y', 'p', 'a', 's', 's'}; - provider.createCredentialEntry( - KEYSTORE_PASSWORD_KEY, storepass); - - char[] trustpass = {'k', 'e', 'y', 'p', 'a', 's', 's'}; - provider.createCredentialEntry( - TRUSTSTORE_PASSWORD_KEY, trustpass); - - char[] certpass = {'k', 'e', 'y', 'p', 'a', 's', 's'}; - provider.createCredentialEntry( - SERVER_CERT_PASSWORD_KEY, certpass); - - // write out so that it can be found in checks - provider.flush(); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - -}
