diff options
author | donald.g.dunne | 2014-09-19 22:55:04 +0000 |
---|---|---|
committer | Angel Avila | 2014-09-19 22:55:04 +0000 |
commit | 4c3dc2ac9ace7272e4b6a08dad5dac99f35f4d72 (patch) | |
tree | 99ad0943712be43978e015ef80cabfa621e84dfa /plugins/org.eclipse.osee.ats.client.integration.tests | |
parent | 938ed972c2b68d5b6474468d9b3a7cc6628a13e7 (diff) | |
download | org.eclipse.osee-4c3dc2ac9ace7272e4b6a08dad5dac99f35f4d72.tar.gz org.eclipse.osee-4c3dc2ac9ace7272e4b6a08dad5dac99f35f4d72.tar.xz org.eclipse.osee-4c3dc2ac9ace7272e4b6a08dad5dac99f35f4d72.zip |
feature[ats_ATS106495]: Add ATS Resource tests
- Standardize how ATS Resources process requests
- Add tests for ATS Resources
- Remove un-needed objects
- Separate json rest calls from ui calls
Change-Id: Ia6fd49df7bc6ad095621f0b46a00d9b494291a02
Diffstat (limited to 'plugins/org.eclipse.osee.ats.client.integration.tests')
8 files changed, 434 insertions, 0 deletions
diff --git a/plugins/org.eclipse.osee.ats.client.integration.tests/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.ats.client.integration.tests/META-INF/MANIFEST.MF index e1526e1faff..0bac10eaa7b 100644 --- a/plugins/org.eclipse.osee.ats.client.integration.tests/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.osee.ats.client.integration.tests/META-INF/MANIFEST.MF @@ -120,6 +120,7 @@ Import-Package: com.google.gson;version="2.1.0", org.eclipse.osee.framework.ui.skynet.widgets.util, org.eclipse.osee.framework.ui.skynet.widgets.xnavigate, org.eclipse.osee.framework.ui.swt, + org.eclipse.osee.jaxrs, org.eclipse.osee.jaxrs.client, org.eclipse.osee.support.test.util, org.osgi.framework diff --git a/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/AtsTest_Ats_Suite.java b/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/AtsTest_Ats_Suite.java index 786acf3357b..e6f70cf4d2a 100644 --- a/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/AtsTest_Ats_Suite.java +++ b/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/AtsTest_Ats_Suite.java @@ -20,6 +20,7 @@ import org.eclipse.osee.ats.client.integration.tests.ats.export.AtsTest_Export_S import org.eclipse.osee.ats.client.integration.tests.ats.health.AtsTest_Health_Suite; import org.eclipse.osee.ats.client.integration.tests.ats.navigate.AtsTest_Navigate_Suite; import org.eclipse.osee.ats.client.integration.tests.ats.render.AtsTest_Renderer_Suite; +import org.eclipse.osee.ats.client.integration.tests.ats.resource.AtsTest_Resource_Suite; import org.eclipse.osee.ats.client.integration.tests.ats.review.AtsTest_Review_Suite; import org.eclipse.osee.ats.client.integration.tests.ats.util.AtsTest_Util_Suite; import org.eclipse.osee.ats.client.integration.tests.ats.workflow.AtsTest_Workflow_Suite; @@ -46,6 +47,7 @@ import org.junit.runners.Suite; AtsTest_Health_Suite.class, AtsTest_Navigate_Suite.class, AtsTest_Renderer_Suite.class, + AtsTest_Resource_Suite.class, AtsTest_Review_Suite.class, AtsTest_Util_Suite.class, AtsTest_Workflow_Suite.class, diff --git a/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/resource/AbstractRestTest.java b/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/resource/AbstractRestTest.java new file mode 100644 index 00000000000..bf83e6ea870 --- /dev/null +++ b/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/resource/AbstractRestTest.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright (c) 2014 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.ats.client.integration.tests.ats.resource; + +import java.net.URI; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriBuilder; +import org.eclipse.osee.framework.core.client.OseeClientProperties; +import org.eclipse.osee.jaxrs.client.JaxRsClient; +import org.junit.Assert; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; + +/** + * @author Donald G. Dunne + */ +public abstract class AbstractRestTest { + + protected JsonObject getObjectNamed(String name, JsonArray array) throws Exception { + for (int x = 0; x < array.size(); x++) { + JsonObject obj = (JsonObject) array.get(x); + JsonElement jsonElement = obj.get("Name"); + if (jsonElement == null) { + jsonElement = obj.get("name"); + } + if (jsonElement.getAsString().equals(name)) { + return obj; + } + } + return null; + } + + protected String getAndCheckStr(String url) { + return getAndCheck(url, MediaType.TEXT_HTML_TYPE); + } + + protected String getAndCheck(String url, MediaType mediaType) { + String appServer = OseeClientProperties.getOseeApplicationServer(); + URI uri = UriBuilder.fromUri(appServer).path(url).build(); + + Response response = JaxRsClient.newClient().target(uri).request(mediaType).get(); + Assert.assertEquals("Unexpected error code: " + response.readEntity(String.class), + javax.ws.rs.core.Response.Status.OK.getStatusCode(), response.getStatus()); + return response.readEntity(String.class); + } + + protected JsonArray getAndCheckArray(String url) throws Exception { + String json = getAndCheck(url, MediaType.APPLICATION_JSON_TYPE); + JsonParser jp = new JsonParser(); + JsonElement je = jp.parse(json); + return (JsonArray) je; + } +} diff --git a/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/resource/ActionResourceTest.java b/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/resource/ActionResourceTest.java new file mode 100644 index 00000000000..904437c8a4c --- /dev/null +++ b/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/resource/ActionResourceTest.java @@ -0,0 +1,177 @@ +/******************************************************************************* + * Copyright (c) 2014 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.ats.client.integration.tests.ats.resource; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.net.URL; +import java.util.Collection; +import javax.ws.rs.client.Entity; +import javax.ws.rs.core.Form; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; +import javax.ws.rs.core.UriBuilder; +import org.eclipse.osee.ats.api.data.AtsAttributeTypes; +import org.eclipse.osee.ats.client.demo.DemoUtil; +import org.eclipse.osee.ats.core.client.team.TeamWorkFlowArtifact; +import org.eclipse.osee.ats.core.util.AtsObjects; +import org.eclipse.osee.ats.core.util.AtsUtilCore; +import org.eclipse.osee.framework.core.client.OseeClientProperties; +import org.eclipse.osee.framework.jdk.core.util.Collections; +import org.eclipse.osee.framework.jdk.core.util.Lib; +import org.eclipse.osee.framework.skynet.core.artifact.Artifact; +import org.eclipse.osee.framework.skynet.core.artifact.search.ArtifactQuery; +import org.eclipse.osee.jaxrs.client.JaxRsClient; +import org.junit.Assert; +import org.junit.Test; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; + +/** + * Test unit for {@link ActionResource} + * + * @author Donald G. Dunne + */ +public class ActionResourceTest extends AbstractRestTest { + + @Test + public void testGet() throws Exception { + String results = getAndCheckStr("/ats/action"); + Assert.assertTrue(results.contains("Action Resource")); + } + + @Test + public void testAtsActionsRestCall() throws Exception { + Collection<TeamWorkFlowArtifact> wfs = DemoUtil.getSawCommittedWfs(); + String atsIds = Collections.toString(",", AtsObjects.toAtsIds(wfs)); + JsonArray array = getAndCheckArray("/ats/action/" + atsIds); + Assert.assertEquals(3, array.size()); + for (JsonElement elment : array) { + JsonObject obj = (JsonObject) elment; + testAction(obj); + } + } + + @Test + public void testAtsActionsDetailsRestCall() throws Exception { + Collection<TeamWorkFlowArtifact> wfs = DemoUtil.getSawCommittedWfs(); + String atsIds = Collections.toString(",", AtsObjects.toAtsIds(wfs)); + JsonArray array = getAndCheckArray("/ats/action/" + atsIds + "/details"); + Assert.assertEquals(3, array.size()); + JsonObject obj = (JsonObject) array.iterator().next(); + testAction(obj); + String atsId = obj.get("AtsId").getAsString(); + Assert.assertEquals(atsId, obj.get("ats.Id").getAsString()); + } + + private void testAction(JsonObject obj) { + Assert.assertEquals(DemoUtil.SAW_COMMITTED_REQT_CHANGES_FOR_DIAGRAM_VIEW, obj.get("Name").getAsString()); + Assert.assertNotNull(obj.has("uuid")); + Assert.assertNotNull(obj.has("AtsId")); + Assert.assertEquals("/ats/ui/action/" + obj.get("AtsId").getAsString(), obj.get("actionLocation").getAsString()); + } + + @Test + public void testAtsActionRestCall() throws Exception { + Collection<TeamWorkFlowArtifact> wfs = DemoUtil.getSawCommittedWfs(); + TeamWorkFlowArtifact teamWf = wfs.iterator().next(); + JsonArray array = getAndCheckArray("/ats/action/" + teamWf.getAtsId()); + Assert.assertEquals(1, array.size()); + JsonObject obj = (JsonObject) array.iterator().next(); + testAction(obj); + } + + @Test + public void testAtsActionDetailsRestCall() throws Exception { + Collection<TeamWorkFlowArtifact> wfs = DemoUtil.getSawCommittedWfs(); + TeamWorkFlowArtifact teamWf = wfs.iterator().next(); + JsonArray array = getAndCheckArray("/ats/action/" + teamWf.getAtsId() + "/details"); + Assert.assertEquals(1, array.size()); + JsonObject obj = (JsonObject) array.iterator().next(); + testAction(obj); + String atsId = obj.get("AtsId").getAsString(); + Assert.assertEquals(atsId, obj.get("ats.Id").getAsString()); + } + + @Test + public void testCreateAction() throws Exception { + + Form form = new Form(); + postAndValidateResponse("title is not valid", form); + + form.param("ats_title", "title"); + postAndValidateResponse("actionableItems is not valid", form); + + form.param("desc", "this is the description"); + postAndValidateResponse("actionableItems is not valid", form); + + form.param("actionableItems", "not valid ai name"); + postAndValidateResponse("actionableItems [not valid ai name] is not valid", form); + + form.asMap().remove("actionableItems"); + form.param("actionableItems", "SAW Code"); + postAndValidateResponse("userId is not valid", form); + + form.param("userId", "asdf"); + postAndValidateResponse("userId [asdf] is not valid", form); + + form.asMap().remove("userId"); + form.param("userId", "Joe Smith"); + postAndValidateResponse("changeType is not valid", form); + + form.param("changeType", "invalid change type"); + postAndValidateResponse("changeType [invalid change type] is not valid", form); + + form.asMap().remove("changeType"); + form.param("changeType", "Improvement"); + postAndValidateResponse("priority is not valid", form); + + form.param("priority", "invalid priority"); + postAndValidateResponse("priority [invalid priority] is not valid", form); + + form.asMap().remove("priority"); + form.param("priority", "3"); + Response response = post(form); + + Assert.assertEquals(Status.SEE_OTHER.getStatusCode(), response.getStatus()); + String urlStr = response.getLocation().toString(); + URL url = new URL(urlStr); + String path = url.getPath(); + Assert.assertTrue(String.format("Invalid url [%s]", url), path.startsWith("/ats/ui/action/ATS")); + String atsId = path.replaceFirst("^.*/", ""); + + Artifact teamArt = + ArtifactQuery.getArtifactFromAttribute(AtsAttributeTypes.AtsId, atsId, AtsUtilCore.getAtsBranch()); + Assert.assertNotNull(teamArt); + } + + private void postAndValidateResponse(String errorMessage, Form form) throws IOException { + Response response = post(form); + validateResponse(response, errorMessage); + } + + private Response post(Form form) { + String appServer = OseeClientProperties.getOseeApplicationServer(); + URI uri = UriBuilder.fromUri(appServer).path("/ats/action").build(); + Response response = + JaxRsClient.newBuilder().followRedirects(false).build().target(uri).request(MediaType.APPLICATION_JSON_TYPE).post( + Entity.form(form)); + return response; + } + + private void validateResponse(Response response, String errorMessage) throws IOException { + Assert.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); + Assert.assertEquals(errorMessage, Lib.inputStreamToString((InputStream) response.getEntity())); + } +} diff --git a/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/resource/ActionUiResourceTest.java b/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/resource/ActionUiResourceTest.java new file mode 100644 index 00000000000..8dbb7fe5fbb --- /dev/null +++ b/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/resource/ActionUiResourceTest.java @@ -0,0 +1,85 @@ +/******************************************************************************* + * Copyright (c) 2014 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.ats.client.integration.tests.ats.resource; + +import java.util.Collection; +import javax.ws.rs.core.MediaType; +import org.eclipse.osee.ats.client.demo.DemoUtil; +import org.eclipse.osee.ats.core.client.team.TeamWorkFlowArtifact; +import org.eclipse.osee.ats.core.util.AtsObjects; +import org.eclipse.osee.framework.jdk.core.util.Collections; +import org.junit.Assert; +import org.junit.Test; + +/** + * Test unit for {@link ActionUiResource} + * + * @author Donald G. Dunne + */ +public class ActionUiResourceTest extends AbstractRestTest { + + @Test + public void testGet() throws Exception { + String results = getAndCheckStr("/ats/ui/action"); + Assert.assertTrue(results.contains("ATS UI Resource")); + } + + @Test + public void getActionError() throws Exception { + String html = getAndCheck("/ats/ui/action/ASDF", MediaType.TEXT_HTML_TYPE); + Assert.assertTrue(html.contains("Action with id(s) [ASDF] can not be found")); + } + + @Test + public void getAction() throws Exception { + Collection<TeamWorkFlowArtifact> wfs = DemoUtil.getSawCommittedWfs(); + TeamWorkFlowArtifact teamWf = wfs.iterator().next(); + String html = getAndCheck("/ats/ui/action/" + teamWf.getAtsId(), MediaType.TEXT_HTML_TYPE); + Assert.assertTrue(html.contains("Title: <b>" + teamWf.getName() + "</b>")); + } + + @Test + public void getActions() throws Exception { + Collection<TeamWorkFlowArtifact> wfs = DemoUtil.getSawCommittedWfs(); + String atsIds = Collections.toString(",", AtsObjects.toAtsIds(wfs)); + String html = getAndCheck("/ats/ui/action/" + atsIds, MediaType.TEXT_HTML_TYPE); + Assert.assertTrue(html.contains("$url='/ats/action/" + atsIds + "/details';")); + } + + @Test + public void getActionDetails() throws Exception { + Collection<TeamWorkFlowArtifact> wfs = DemoUtil.getSawCommittedWfs(); + TeamWorkFlowArtifact teamWf = wfs.iterator().next(); + String html = getAndCheck("/ats/ui/action/" + teamWf.getAtsId() + "/details", MediaType.TEXT_HTML_TYPE); + Assert.assertTrue(html.contains("Artifact Type: <b>" + teamWf.getArtifactTypeName() + "</b>")); + } + + @Test + public void getActionDetailsError() throws Exception { + Collection<TeamWorkFlowArtifact> wfs = DemoUtil.getSawCommittedWfs(); + String atsIds = Collections.toString(",", AtsObjects.toAtsIds(wfs)); + String html = getAndCheck("/ats/ui/action/" + atsIds + "/details", MediaType.TEXT_HTML_TYPE); + Assert.assertTrue(html.contains("can not be found")); + } + + @Test + public void getNewAction() throws Exception { + String html = getAndCheck("/ats/ui/action/NewAction", MediaType.TEXT_HTML_TYPE); + Assert.assertTrue(html.contains("ATS - Create new ATS Action")); + } + + @Test + public void getSearch() throws Exception { + String html = getAndCheck("/ats/ui/action/Search", MediaType.TEXT_HTML_TYPE); + Assert.assertTrue(html.contains("ATS - Search by Id")); + } + +} diff --git a/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/resource/AtsTest_Resource_Suite.java b/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/resource/AtsTest_Resource_Suite.java new file mode 100644 index 00000000000..b97f871d5bc --- /dev/null +++ b/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/resource/AtsTest_Resource_Suite.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.ats.client.integration.tests.ats.resource; + +import org.eclipse.osee.ats.client.integration.tests.util.DemoTestUtil; +import org.eclipse.osee.framework.jdk.core.util.OseeProperties; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +@RunWith(Suite.class) +@Suite.SuiteClasses({ + ActionResourceTest.class, + ActionUiResourceTest.class, + ConvertResourceTest.class, + UserResourceTest.class}) +/** + * This test suite contains test that can be run against any production db + * + * @author Donald G. Dunne + */ +public class AtsTest_Resource_Suite { + @BeforeClass + public static void setUp() throws Exception { + OseeProperties.setIsInTest(true); + System.out.println("\n\nBegin " + AtsTest_Resource_Suite.class.getSimpleName()); + DemoTestUtil.setUpTest(); + } + + @AfterClass + public static void tearDown() throws Exception { + System.out.println("End " + AtsTest_Resource_Suite.class.getSimpleName()); + } +} diff --git a/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/resource/ConvertResourceTest.java b/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/resource/ConvertResourceTest.java new file mode 100644 index 00000000000..544a40a1b04 --- /dev/null +++ b/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/resource/ConvertResourceTest.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2014 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.ats.client.integration.tests.ats.resource; + +import org.junit.Assert; +import org.junit.Test; + +/** + * Test unit for {@link ConvertResource} + * + * @author Donald G. Dunne + */ +public class ConvertResourceTest extends AbstractRestTest { + + @Test + public void testGet() throws Exception { + String results = getAndCheckStr("/ats/convert"); + Assert.assertTrue(results.contains("ATS - Conversions")); + } + +} diff --git a/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/resource/UserResourceTest.java b/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/resource/UserResourceTest.java new file mode 100644 index 00000000000..a4cc4e2d0ee --- /dev/null +++ b/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/resource/UserResourceTest.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2014 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.ats.client.integration.tests.ats.resource; + +import org.junit.Assert; +import org.junit.Test; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; + +/** + * Test unit for {@link UserResource} + * + * @author Donald G. Dunne + */ +public class UserResourceTest extends AbstractRestTest { + + @Test + public void testGet() throws Exception { + JsonArray users = getAndCheckArray("/ats/user"); + Assert.assertEquals(23, users.size()); + JsonObject obj = getObjectNamed("Joe Smith", users); + Assert.assertEquals("Joe Smith", obj.get("uuid").getAsString()); + } + +} |