aboutsummaryrefslogtreecommitdiffstats
path: root/client/client-editor/src/test/java
diff options
context:
space:
mode:
authorramverma <ram.krishna.verma@ericsson.com>2018-07-13 12:32:32 +0100
committerramverma <ram.krishna.verma@ericsson.com>2018-07-13 16:07:05 +0100
commit08b595c863b45e759e57ef419c83dad2b209df9c (patch)
tree02f9c3e7c74e5b1242d4a04c21ade4e4ea501063 /client/client-editor/src/test/java
parent7fbb46185166f2699b624cd2616c6fdd74ef4832 (diff)
Adding client editor module to apex-pdp
The size of the review is big because of following: 1. edit_area & jquery are 3PP's used in the client editor 2. ui elements like svg, gifs, png Change-Id: Ib62d8e6dda6e6dc1b6e604298e23505523f77cf2 Issue-ID: POLICY-864 Signed-off-by: ramverma <ram.krishna.verma@ericsson.com>
Diffstat (limited to 'client/client-editor/src/test/java')
-rw-r--r--client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/RestInterfaceTest.java212
-rw-r--r--client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/TestApexEditorRestResource.java1497
-rw-r--r--client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/TestApexEditorStartup.java441
-rw-r--r--client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/TestExceptions.java41
-rw-r--r--client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/bean/BeanFake.java47
-rw-r--r--client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/bean/TestBeans.java87
6 files changed, 2325 insertions, 0 deletions
diff --git a/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/RestInterfaceTest.java b/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/RestInterfaceTest.java
new file mode 100644
index 000000000..eeefa4b95
--- /dev/null
+++ b/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/RestInterfaceTest.java
@@ -0,0 +1,212 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.client.editor.rest;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.Invocation.Builder;
+import javax.ws.rs.client.WebTarget;
+import javax.xml.bind.JAXBException;
+
+import org.eclipse.persistence.jpa.jpql.Assert;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.onap.policy.apex.client.editor.rest.ApexEditorMain.EditorState;
+import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
+import org.onap.policy.apex.model.basicmodel.handling.ApexModelReader;
+import org.onap.policy.apex.model.basicmodel.handling.ApexModelStringWriter;
+import org.onap.policy.apex.model.modelapi.ApexAPIResult;
+import org.onap.policy.apex.model.policymodel.concepts.AxPolicy;
+import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
+import org.onap.policy.apex.model.utilities.ResourceUtils;
+
+/**
+ * The RestInterface Test.
+ */
+public class RestInterfaceTest {
+ // CHECKSTYLE:OFF: MagicNumber
+
+ private static final String TESTMODELFILE = "models/SamplePolicyModelMVEL.json";
+ private static final String TESTPORTNUM = "18989";
+ private static final long MAX_WAIT = 15000; // 15 sec
+ private static final InputStream SYSIN = System.in;
+ private static final String[] EDITOR_MAIN_ARGS = new String[] { "-p", TESTPORTNUM };
+
+ private static ApexEditorMain editorMain;
+ private static WebTarget target;
+
+ private static AxPolicyModel localmodel = null;
+ private static String localmodelString = null;
+
+ /**
+ * Sets up the tests.
+ *
+ * @throws Exception if an error happens
+ */
+ @BeforeClass
+ public static void setUp() throws Exception {
+ // Start the editor
+ editorMain = new ApexEditorMain(EDITOR_MAIN_ARGS, System.out);
+ // prevent a stray stdin value from killing the editor
+ final ByteArrayInputStream input = new ByteArrayInputStream("".getBytes());
+ System.setIn(input);
+ // Init the editor in a separate thread
+ final Runnable testThread = new Runnable() {
+ @Override
+ public void run() {
+ editorMain.init();
+ }
+ };
+ new Thread(testThread).start();
+ // wait until editorMain is in state RUNNING
+ final long startwait = System.currentTimeMillis();
+ while (editorMain.getState().equals(EditorState.STOPPED) || editorMain.getState().equals(EditorState.READY)
+ || editorMain.getState().equals(EditorState.INITIALIZING)) {
+ if (editorMain.getState().equals(EditorState.STOPPED)) {
+ Assert.fail("Rest endpoint (" + editorMain + ") shut down before it could be used");
+ }
+ if (System.currentTimeMillis() - startwait > MAX_WAIT) {
+ Assert.fail("Rest endpoint (" + editorMain + ") for test failed to start fast enough");
+ }
+ Thread.sleep(100);
+ }
+
+ // create the client
+ final Client c = ClientBuilder.newClient();
+ // Create the web target
+ target = c.target(new ApexEditorParameters().getBaseURI());
+
+ // load a test model locally
+ localmodel = new ApexModelReader<>(AxPolicyModel.class, false)
+ .read(ResourceUtils.getResourceAsStream(TESTMODELFILE));
+ localmodelString =
+ new ApexModelStringWriter<AxPolicyModel>(false).writeJSONString(localmodel, AxPolicyModel.class);
+
+ // initialize a session ID
+ createNewSession();
+ }
+
+ /**
+ * Clean up streams.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ * @throws InterruptedException the interrupted exception
+ */
+ @AfterClass
+ public static void cleanUpStreams() throws IOException, InterruptedException {
+ editorMain.shutdown();
+ // wait until editorMain is in state STOPPED
+ final long startwait = System.currentTimeMillis();
+ while (!editorMain.getState().equals(EditorState.STOPPED)) {
+ if (System.currentTimeMillis() - startwait > MAX_WAIT) {
+ Assert.fail("Rest endpoint (" + editorMain + ") for test failed to shutdown fast enough");
+ }
+ Thread.sleep(50);
+ }
+ System.setIn(SYSIN);
+ }
+
+ /**
+ * Test to see that the message create Model with model id -1 .
+ */
+ @Test
+ public void createSession() {
+ createNewSession();
+ }
+
+ /**
+ * Creates a new session.
+ *
+ * @return the session ID
+ */
+ private static int createNewSession() {
+ final ApexAPIResult responseMsg = target.path("editor/-1/Session/Create").request().get(ApexAPIResult.class);
+ assertEquals(responseMsg.getResult(), ApexAPIResult.RESULT.SUCCESS);
+ assertTrue(responseMsg.getMessages().size() == 1);
+ return Integer.parseInt(responseMsg.getMessages().get(0));
+ }
+
+ /**
+ * Upload policy.
+ *
+ * @param sessionID the session ID
+ * @param modelAsJsonString the model as json string
+ */
+ private void uploadPolicy(final int sessionID, final String modelAsJsonString) {
+ final Builder requestbuilder = target.path("editor/" + sessionID + "/Model/Load").request();
+ final ApexAPIResult responseMsg = requestbuilder.put(Entity.json(modelAsJsonString), ApexAPIResult.class);
+ assertTrue(responseMsg.isOK());
+ }
+
+ /**
+ * Create a new session, Upload a test policy model, then get a policy, parse it, and compare it to the same policy
+ * in the original model.
+ *
+ * @throws ApexException if there is an Apex Error
+ * @throws JAXBException if there is a JaxB Error
+ **/
+ @Test
+ public void testUploadThenGet() throws ApexException, JAXBException {
+
+ final int sessionID = createNewSession();
+
+ uploadPolicy(sessionID, localmodelString);
+
+ final ApexAPIResult responseMsg = target.path("editor/" + sessionID + "/Policy/Get")
+ .queryParam("name", "Policy0").queryParam("version", "0.0.1").request().get(ApexAPIResult.class);
+ assertTrue(responseMsg.isOK());
+
+ // The string in responseMsg.Messages[0] is a JSON representation of a AxPolicy object. Lets parse it
+ final String returnedPolicyAsString = responseMsg.getMessages().get(0);
+ ApexModelReader<AxPolicy> apexPolicyReader = new ApexModelReader<>(AxPolicy.class, false);
+ final AxPolicy returnedpolicy = apexPolicyReader.read(returnedPolicyAsString);
+ // AxPolicy returnedpolicy = RestUtils.getConceptFromJSON(returnedPolicyAsString, AxPolicy.class);
+
+ // Extract the local copy of that policy from the local Apex Policy Model
+ final AxPolicy localpolicy = localmodel.getPolicies().get("Policy0", "0.0.1");
+
+ // Write that local copy of the AxPolicy object to a Json String, ten parse it again
+ final ApexModelStringWriter<AxPolicy> apexModelWriter = new ApexModelStringWriter<>(false);
+ final String localPolicyString = apexModelWriter.writeJSONString(localpolicy, AxPolicy.class);
+ apexPolicyReader = new ApexModelReader<>(AxPolicy.class, false);
+ final AxPolicy localpolicyReparsed = apexPolicyReader.read(localPolicyString);
+ // AxPolicy localpolicy_reparsed = RestUtils.getConceptFromJSON(returnedPolicyAsString, AxPolicy.class);
+
+ assertNotNull(returnedpolicy);
+ assertNotNull(localpolicy);
+ assertNotNull(localpolicyReparsed);
+ assertEquals(localpolicy, localpolicyReparsed);
+ assertEquals(localpolicy, returnedpolicy);
+ }
+
+ // TODO Full unit testing of REST interface
+
+}
diff --git a/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/TestApexEditorRestResource.java b/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/TestApexEditorRestResource.java
new file mode 100644
index 000000000..ee156e02b
--- /dev/null
+++ b/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/TestApexEditorRestResource.java
@@ -0,0 +1,1497 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.client.editor.rest;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import java.io.IOException;
+
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.MediaType;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.JerseyTest;
+import org.junit.Test;
+import org.onap.policy.apex.model.modelapi.ApexAPIResult;
+import org.onap.policy.apex.model.modelapi.ApexAPIResult.RESULT;
+import org.onap.policy.apex.model.utilities.TextFileUtils;
+
+/**
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class TestApexEditorRestResource extends JerseyTest {
+ @Override
+ protected Application configure() {
+ return new ResourceConfig(ApexEditorRestResource.class);
+ }
+
+ @Test
+ public void testSessionCreate() {
+ ApexAPIResult result = target("editor/-2/Session/Create").request().get(ApexAPIResult.class);
+ assertEquals(RESULT.FAILED, result.getResult());
+
+ result = target("editor/-1/Session/Create").request().get(ApexAPIResult.class);
+ assertEquals(RESULT.SUCCESS, result.getResult());
+ final int sessionId = new Integer(result.getMessages().get(0));
+
+ result = target("editor/-1/Session/Create").request().get(ApexAPIResult.class);
+ assertEquals(RESULT.SUCCESS, result.getResult());
+
+ final int corruptSessionId = ApexEditorRestResource.createCorruptSession();
+
+ try {
+ target("editor/" + corruptSessionId + "/Model/Analyse").request().get(ApexAPIResult.class);
+ } catch (final Exception e) {
+ assertEquals("HTTP 500 Request failed.", e.getMessage());
+ }
+
+ result = target("editor/" + sessionId + "/Model/Analyse").request().get(ApexAPIResult.class);
+ assertEquals(RESULT.SUCCESS, result.getResult());
+ result = target("editor/-12345/Model/Analyse").request().get(ApexAPIResult.class);
+ assertEquals(RESULT.FAILED, result.getResult());
+ result = target("editor/12345/Model/Analyse").request().get(ApexAPIResult.class);
+ assertEquals(RESULT.FAILED, result.getResult());
+
+ try {
+ target("editor/" + corruptSessionId + "/Model/Validate").request().get(ApexAPIResult.class);
+ } catch (final Exception e) {
+ assertEquals("HTTP 500 Request failed.", e.getMessage());
+ }
+
+ result = target("editor/" + sessionId + "/Model/Validate").request().get(ApexAPIResult.class);
+ assertEquals(RESULT.FAILED, result.getResult());
+ result = target("editor/-12345/Model/Validate").request().get(ApexAPIResult.class);
+ assertEquals(RESULT.FAILED, result.getResult());
+ result = target("editor/12345/Model/Validate").request().get(ApexAPIResult.class);
+ assertEquals(RESULT.FAILED, result.getResult());
+
+ final String modelString = "{" + "\"name\" : \"Hello\"," + "\"version\" : \"0.0.2\","
+ + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002699\","
+ + "\"description\" : \"A description of the model\"" + "}";
+ final Entity<String> csEntity = Entity.entity(modelString, MediaType.APPLICATION_JSON);
+ result = target("editor/-12345/Model/Create").request().post(csEntity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ result = target("editor/-12345/Model/Create").request().post(csEntity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ result = target("editor/1234545/Model/Create").request().post(csEntity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ result = target("editor/" + sessionId + "/Model/Create").request().post(csEntity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ try {
+ target("editor/" + corruptSessionId + "/Model/Create").request().post(csEntity, ApexAPIResult.class);
+ } catch (final Exception e) {
+ assertEquals("HTTP 500 Request failed.", e.getMessage());
+ }
+
+ result = target("editor/-12345/Model/Update").request().put(csEntity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ result = target("editor/-12345/Model/Update").request().put(csEntity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ result = target("editor/1234545/Model/Update").request().put(csEntity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ result = target("editor/" + sessionId + "/Model/Update").request().put(csEntity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ try {
+ target("editor/" + corruptSessionId + "/Model/Update").request().put(csEntity, ApexAPIResult.class);
+ } catch (final Exception e) {
+ assertEquals("HTTP 500 Request failed.", e.getMessage());
+ }
+
+ try {
+ result = target("editor/" + corruptSessionId + "/Model/GetKey").request().get(ApexAPIResult.class);
+ } catch (final Exception e) {
+ assertEquals("HTTP 500 Request failed.", e.getMessage());
+ }
+
+ result = target("editor/" + sessionId + "/Model/GetKey").request().get(ApexAPIResult.class);
+ assertEquals(RESULT.SUCCESS, result.getResult());
+ result = target("editor/-12345/Model/GetKey").request().get(ApexAPIResult.class);
+ assertEquals(RESULT.FAILED, result.getResult());
+ result = target("editor/12345/Model/GetKey").request().get(ApexAPIResult.class);
+ assertEquals(RESULT.FAILED, result.getResult());
+
+ try {
+ result = target("editor/" + corruptSessionId + "/Model/Get").request().get(ApexAPIResult.class);
+ } catch (final Exception e) {
+ assertEquals("HTTP 500 Request failed.", e.getMessage());
+ }
+
+ result = target("editor/" + sessionId + "/Model/Get").request().get(ApexAPIResult.class);
+ assertEquals(RESULT.SUCCESS, result.getResult());
+ result = target("editor/-12345/Model/Get").request().get(ApexAPIResult.class);
+ assertEquals(RESULT.FAILED, result.getResult());
+ result = target("editor/12345/Model/Get").request().get(ApexAPIResult.class);
+ assertEquals(RESULT.FAILED, result.getResult());
+
+ try {
+ result = target("editor/" + corruptSessionId + "/Model/Download").request().get(ApexAPIResult.class);
+ } catch (final Exception e) {
+ assertEquals("HTTP 500 Request failed.", e.getMessage());
+ }
+
+ result = target("editor/" + sessionId + "/Model/Download").request().get(ApexAPIResult.class);
+ assertEquals(RESULT.SUCCESS, result.getResult());
+ try {
+ target("editor/-12345/Model/Download").request().get(ApexAPIResult.class);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertEquals("HTTP 500 Request failed.", e.getMessage());
+ }
+ try {
+ target("editor/12345/Model/Download").request().get(ApexAPIResult.class);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertEquals("HTTP 500 Request failed.", e.getMessage());
+ }
+
+ try {
+ result = target("editor/" + corruptSessionId + "/KeyInformation/Get").request().get(ApexAPIResult.class);
+ } catch (final Exception e) {
+ assertEquals("HTTP 500 Request failed.", e.getMessage());
+ }
+
+ result = target("editor/" + sessionId + "/KeyInformation/Get").request().get(ApexAPIResult.class);
+ assertEquals(RESULT.SUCCESS, result.getResult());
+ result = target("editor/-12345/KeyInformation/Get").request().get(ApexAPIResult.class);
+ assertEquals(RESULT.FAILED, result.getResult());
+ result = target("editor/12345/KeyInformation/Get").request().get(ApexAPIResult.class);
+ assertEquals(RESULT.FAILED, result.getResult());
+
+ try {
+ result = target("editor/" + corruptSessionId + "/Model/Delete").request().delete(ApexAPIResult.class);
+ } catch (final Exception e) {
+ assertEquals("HTTP 500 Request failed.", e.getMessage());
+ }
+
+ result = target("editor/" + sessionId + "/Model/Delete").request().delete(ApexAPIResult.class);
+ assertEquals(RESULT.SUCCESS, result.getResult());
+ result = target("editor/-12345/Model/Delete").request().delete(ApexAPIResult.class);
+ assertEquals(RESULT.FAILED, result.getResult());
+ result = target("editor/12345/Model/Delete").request().delete(ApexAPIResult.class);
+ assertEquals(RESULT.FAILED, result.getResult());
+ }
+
+ @Test
+ public void testContextSchema() throws IOException {
+ ApexAPIResult result = target("editor/-1/Session/Create").request().get(ApexAPIResult.class);
+ assertEquals(RESULT.SUCCESS, result.getResult());
+ final int sessionId = new Integer(result.getMessages().get(0));
+
+ final int corruptSessionId = ApexEditorRestResource.createCorruptSession();
+
+ result = target("editor/-12345/Validate/ContextSchema").request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ try {
+ target("editor/" + corruptSessionId + "/Validate/ContextSchema").request().get(ApexAPIResult.class);
+ } catch (final Exception e) {
+ assertEquals("HTTP 500 Request failed.", e.getMessage());
+ }
+
+ result = target("editor/" + sessionId + "/Validate/ContextSchema").request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = target("editor/" + sessionId + "/Validate/ContextSchema").queryParam("name", (String) null)
+ .queryParam("version", (String) null).request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = target("editor/" + sessionId + "/Validate/ContextSchema").queryParam("name", "%%%$£")
+ .queryParam("version", (String) null).request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ final String modelString = TextFileUtils.getTextFileAsString("src/test/resources/models/PolicyModel.json");
+
+ Entity<String> modelEntity = Entity.entity("Somewhere over the rainbow", MediaType.APPLICATION_JSON);
+ result = target("editor/" + -12345 + "/Model/Load").request().put(modelEntity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ result = target("editor/" + 12345 + "/Model/Load").request().put(modelEntity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ result = target("editor/" + sessionId + "/Model/Load").request().put(modelEntity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ modelEntity = Entity.entity("", MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Model/Load").request().put(modelEntity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ modelEntity = Entity.entity(modelString, MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Model/Load").request().put(modelEntity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+ result = target("editor/" + sessionId + "/ContextSchema/Get").queryParam("name", (String) null)
+ .queryParam("version", (String) null).request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ try {
+ target("editor/" + corruptSessionId + "/ContextSchema/Get").queryParam("name", (String) null)
+ .queryParam("version", (String) null).request().get(ApexAPIResult.class);
+ } catch (final Exception e) {
+ assertEquals("HTTP 500 Request failed.", e.getMessage());
+ }
+
+ String csString = "{" + "\"name\" : \"Hello\"," + "\"version\" : \"0.0.2\","
+ + "\"schemaFlavour\" : \"Java\"," + "\"schemaDefinition\" : \"java.lang.String\","
+ + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ Entity<String> csEntity = Entity.entity(csString, MediaType.APPLICATION_JSON);
+ result = target("editor/-12345/ContextSchema/Create").request().post(csEntity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ result = target("editor/1234545/ContextSchema/Create").request().post(csEntity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ result = target("editor/" + sessionId + "/ContextSchema/Create").request().post(csEntity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ try {
+ target("editor/" + corruptSessionId + "/ContextSchema/Create").request().post(csEntity,
+ ApexAPIResult.class);
+ } catch (final Exception e) {
+ assertEquals("HTTP 500 Request failed.", e.getMessage());
+ }
+
+ csString = "{" + "\"name\" : \"Hello\"," + "\"version\" : \"0.0.2\","
+ + "\"schemaFlavour\" : \"Java\"," + "\"schemaDefinition\" : \"my.perfect.String\","
+ + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ csEntity = Entity.entity(csString, MediaType.APPLICATION_JSON);
+ result = target("editor/-12345/ContextSchema/Update").request().put(csEntity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ result = target("editor/1234545/ContextSchema/Update").request().put(csEntity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ result = target("editor/" + sessionId + "/ContextSchema/Update").request().put(csEntity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ try {
+ target("editor/" + corruptSessionId + "/ContextSchema/Update").request().put(csEntity, ApexAPIResult.class);
+ } catch (final Exception e) {
+ assertEquals("HTTP 500 Request failed.", e.getMessage());
+ }
+
+ result = target("editor/" + sessionId + "/ContextSchema/Get").queryParam("name", "Hello")
+ .queryParam("version", (String) null).request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+ result = target("editor/" + sessionId + "/ContextSchema/Get").queryParam("name", "NonExistant")
+ .queryParam("version", (String) null).request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = target("editor/-123345/ContextSchema/Get").queryParam("name", (String) null)
+ .queryParam("version", (String) null).request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ result = target("editor/123345/ContextSchema/Get").queryParam("name", (String) null)
+ .queryParam("version", (String) null).request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ try {
+ target("editor/" + corruptSessionId + "/ContextSchema/Get").queryParam("name", "Hello")
+ .queryParam("version", (String) null).request().get(ApexAPIResult.class);
+ } catch (final Exception e) {
+ assertEquals("HTTP 500 Request failed.", e.getMessage());
+ }
+
+ result = target("editor/" + sessionId + "/Validate/ContextSchema").queryParam("name", (String) null)
+ .queryParam("version", (String) null).request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ try {
+ target("editor/" + corruptSessionId + "/ContextSchema/Delete").queryParam("name", "Hello")
+ .queryParam("version", "0.0.2").request().delete(ApexAPIResult.class);
+ } catch (final Exception e) {
+ assertEquals("HTTP 500 Request failed.", e.getMessage());
+ }
+
+ result = target("editor/-123345/ContextSchema/Delete").queryParam("name", (String) null)
+ .queryParam("version", (String) null).request().delete(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ result = target("editor/123345/ContextSchema/Delete").queryParam("name", (String) null)
+ .queryParam("version", (String) null).request().delete(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ result = target("editor/" + sessionId + "/ContextSchema/Delete").queryParam("name", "Hello")
+ .queryParam("version", "0.0.2").request().delete(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+ result = target("editor/" + sessionId + "/ContextSchema/Delete").queryParam("name", (String) null)
+ .queryParam("version", (String) null).request().delete(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+ }
+
+ @Test
+ public void testContextAlbum() throws IOException {
+ ApexAPIResult result = target("editor/-1/Session/Create").request().get(ApexAPIResult.class);
+ assertEquals(RESULT.SUCCESS, result.getResult());
+ final int sessionId = new Integer(result.getMessages().get(0));
+ final int corruptSessionId = ApexEditorRestResource.createCorruptSession();
+
+ result = target("editor/-12345/Validate/ContextAlbum").request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ try {
+ target("editor/" + corruptSessionId + "/Validate/ContextAlbum").request().get(ApexAPIResult.class);
+ } catch (final Exception e) {
+ assertEquals("HTTP 500 Request failed.", e.getMessage());
+ }
+
+ result = target("editor/" + sessionId + "/Validate/ContextAlbum").request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ result = target("editor/" + sessionId + "/Validate/ContextAlbum").queryParam("name", (String) null)
+ .queryParam("version", (String) null).request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ result = target("editor/" + sessionId + "/Validate/ContextAlbum").queryParam("name", "%%%$£")
+ .queryParam("version", (String) null).request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ final String modelString = TextFileUtils.getTextFileAsString("src/test/resources/models/PolicyModel.json");
+
+ Entity<String> modelEntity = Entity.entity("Somewhere over the rainbow", MediaType.APPLICATION_JSON);
+ result = target("editor/" + -12345 + "/Model/Load").request().put(modelEntity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ result = target("editor/" + 12345 + "/Model/Load").request().put(modelEntity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ result = target("editor/" + sessionId + "/Model/Load").request().put(modelEntity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ modelEntity = Entity.entity("", MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Model/Load").request().put(modelEntity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ modelEntity = Entity.entity(modelString, MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Model/Load").request().put(modelEntity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+ result = target("editor/" + sessionId + "/ContextAlbum/Get").queryParam("name", (String) null)
+ .queryParam("version", (String) null).request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ String caString = "{" + "\"name\" : \"Hello\"," + "\"version\" : \"0.0.2\","
+ + "\"scope\" : \"Domain\"," + "\"writeable\" : false,"
+ + "\"itemSchema\" : {\"name\" : \"StringType\", \"version\" : \"0.0.1\"},"
+ + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ Entity<String> caEntity = Entity.entity(caString, MediaType.APPLICATION_JSON);
+ result = target("editor/-12345/ContextAlbum/Create").request().post(caEntity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ result = target("editor/1234545/ContextAlbum/Create").request().post(caEntity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ result = target("editor/" + sessionId + "/ContextAlbum/Create").request().post(caEntity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ try {
+ target("editor/" + corruptSessionId + "/ContextAlbum/Create").request().post(caEntity, ApexAPIResult.class);
+ } catch (final Exception e) {
+ assertEquals("HTTP 500 Request failed.", e.getMessage());
+ }
+
+ caString = "{" + "\"name\" : \"Hello\"," + "\"version\" : \"0.0.2\","
+ + "\"scope\" : \"Global\"," + "\"writeable\" : false,"
+ + "\"itemSchema\" : {\"name\" : \"StringType\", \"version\" : \"0.0.1\"},"
+ + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ caEntity = Entity.entity(caString, MediaType.APPLICATION_JSON);
+ result = target("editor/-12345/ContextAlbum/Update").request().put(caEntity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ result = target("editor/1234545/ContextAlbum/Update").request().put(caEntity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ result = target("editor/" + sessionId + "/ContextAlbum/Update").request().put(caEntity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ try {
+ target("editor/" + corruptSessionId + "/ContextAlbum/Update").request().put(caEntity, ApexAPIResult.class);
+ } catch (final Exception e) {
+ assertEquals("HTTP 500 Request failed.", e.getMessage());
+ }
+
+ try {
+ target("editor/" + corruptSessionId + "/ContextAlbum/Get").queryParam("name", "Hello")
+ .queryParam("version", (String) null).request().get(ApexAPIResult.class);
+ } catch (final Exception e) {
+ assertEquals("HTTP 500 Request failed.", e.getMessage());
+ }
+
+ result = target("editor/" + sessionId + "/ContextAlbum/Get").queryParam("name", "Hello")
+ .queryParam("version", (String) null).request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+ result = target("editor/" + sessionId + "/ContextAlbum/Get").queryParam("name", "IDontExist")
+ .queryParam("version", (String) null).request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = target("editor/-123345/ContextAlbum/Get").queryParam("name", (String) null)
+ .queryParam("version", (String) null).request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ result = target("editor/123345/ContextAlbum/Get").queryParam("name", (String) null)
+ .queryParam("version", (String) null).request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ result = target("editor/" + sessionId + "/Validate/ContextAlbum").queryParam("name", (String) null)
+ .queryParam("version", (String) null).request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ try {
+ target("editor/" + corruptSessionId + "/ContextAlbum/Delete").queryParam("name", (String) null)
+ .queryParam("version", (String) null).request().delete(ApexAPIResult.class);
+ } catch (final Exception e) {
+ assertEquals("HTTP 500 Request failed.", e.getMessage());
+ }
+
+ result = target("editor/-123345/ContextAlbum/Delete").queryParam("name", (String) null)
+ .queryParam("version", (String) null).request().delete(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ result = target("editor/123345/ContextAlbum/Delete").queryParam("name", (String) null)
+ .queryParam("version", (String) null).request().delete(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ result = target("editor/" + sessionId + "/ContextAlbum/Delete").queryParam("name", "Hello")
+ .queryParam("version", "0.0.2").request().delete(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+ result = target("editor/" + sessionId + "/ContextAlbum/Delete").queryParam("name", (String) null)
+ .queryParam("version", (String) null).request().delete(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+ }
+
+ @Test
+ public void testEvent() throws IOException {
+ final int corruptSessionId = ApexEditorRestResource.createCorruptSession();
+
+ ApexAPIResult result = target("editor/-1/Session/Create").request().get(ApexAPIResult.class);
+ assertEquals(RESULT.SUCCESS, result.getResult());
+ final int sessionId = new Integer(result.getMessages().get(0));
+
+ result = target("editor/-12345/Validate/Event").request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ result = target("editor/" + sessionId + "/Validate/Event").request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ try {
+ target("editor/" + corruptSessionId + "/Validate/Event").request().get(ApexAPIResult.class);
+ } catch (final Exception e) {
+ assertEquals("HTTP 500 Request failed.", e.getMessage());
+ }
+
+ result = target("editor/" + sessionId + "/Validate/Event").queryParam("name", (String) null)
+ .queryParam("version", (String) null).request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ result = target("editor/" + sessionId + "/Validate/Event").queryParam("name", "%%%$£")
+ .queryParam("version", (String) null).request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ final String modelString = TextFileUtils.getTextFileAsString("src/test/resources/models/PolicyModel.json");
+
+ Entity<String> modelEntity = Entity.entity("Somewhere over the rainbow", MediaType.APPLICATION_JSON);
+ result = target("editor/" + -12345 + "/Model/Load").request().put(modelEntity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ result = target("editor/" + 12345 + "/Model/Load").request().put(modelEntity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ result = target("editor/" + sessionId + "/Model/Load").request().put(modelEntity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ modelEntity = Entity.entity("", MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Model/Load").request().put(modelEntity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ modelEntity = Entity.entity(modelString, MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Model/Load").request().put(modelEntity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+ result = target("editor/" + sessionId + "/Event/Get").queryParam("name", (String) null)
+ .queryParam("version", (String) null).request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ String entityString = "{" + "\"name\" : \"Hello\"," + "\"version\" : \"0.0.2\","
+ + "\"namespace\" : \"somewhere.over.the.rainbow\"," + "\"source\" : \"beginning\","
+ + "\"target\" : \"end\"," + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ Entity<String> entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/-12345/Event/Create").request().post(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ result = target("editor/1234545/Event/Create").request().post(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ result = target("editor/" + sessionId + "/Event/Create").request().post(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+ result = target("editor/" + sessionId + "/Event/Create").request().post(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.CONCEPT_EXISTS, result.getResult());
+
+ try {
+ target("editor/" + corruptSessionId + "/Event/Create").request().post(entity, ApexAPIResult.class);
+ } catch (final Exception e) {
+ assertEquals("HTTP 500 Request failed.", e.getMessage());
+ }
+
+ entityString = "{" + "\"name\" : \"Hiya\"," + "\"version\" : \"0.0.2\","
+ + "\"namespace\" : \"somewhere.over.the.rainbow\"," + "\"source\" : \"beginning\","
+ + "\"target\" : \"end\"," + "\"parameters\" : {},"
+ + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002799\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Event/Create").request().post(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ entityString = "{" + "\"name\" : \"HowsItGoing\"," + "\"version\" : \"0.0.2\","
+ + "\"namespace\" : \"somewhere.over.the.rainbow\"," + "\"source\" : \"beginning\","
+ + "\"target\" : \"end\","
+ + "\"parameters\" : {\"Par0\" : {\"name\" : \"StringType\", \"version\" : \"0.0.1\", \"localName\" : \"Par0\", \"optional\" : false}},"
+ + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002799\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Event/Create").request().post(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ entityString = "{" + "\"name\" : \"Hi\"," + "\"version\" : \"0.0.2\","
+ + "\"namespace\" : \"somewhere.over.the.rainbow\"," + "\"source\" : \"beginning\","
+ + "\"target\" : \"end\"," + "\"parameters\" : {\"Par0\" : null},"
+ + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002799\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Event/Create").request().post(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ entityString = "{" + "\"name\" : \"GoodDay\"," + "\"version\" : \"0.0.2\","
+ + "\"namespace\" : \"somewhere.over.the.rainbow\"," + "\"source\" : \"beginning\","
+ + "\"target\" : \"end\","
+ + "\"parameters\" : {\"Par0\" : {\"name\" : \"NonExistantType\", \"version\" : \"0.0.1\", \"localName\" : \"Par0\", \"optional\" : false}},"
+ + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002799\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Event/Create").request().post(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ entityString = "{" + "\"name\" : \"Hello\"," + "\"version\" : \"0.0.2\","
+ + "\"namespace\" : \"somewhere.over.someone.elses.rainbow\","
+ + "\"source\" : \"start\"," + "\"target\" : \"finish\","
+ + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/-12345/Event/Update").request().put(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ result = target("editor/1234545/Event/Update").request().put(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ result = target("editor/" + sessionId + "/Event/Update").request().put(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ try {
+ target("editor/" + corruptSessionId + "/Event/Update").request().put(entity, ApexAPIResult.class);
+ } catch (final Exception e) {
+ assertEquals("HTTP 500 Request failed.", e.getMessage());
+ }
+
+ entityString = "{" + "\"name\" : null," + "\"version\" : \"0.0.2\","
+ + "\"namespace\" : \"somewhere.over.someone.elses.rainbow\","
+ + "\"source\" : \"start\"," + "\"target\" : \"finish\","
+ + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Event/Update").request().put(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ entityString = "{" + "\"name\" : \"NonExistantEvent\"," + "\"version\" : \"0.0.2\","
+ + "\"namespace\" : \"somewhere.over.someone.elses.rainbow\","
+ + "\"source\" : \"start\"," + "\"target\" : \"finish\","
+ + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Event/Update").request().put(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = target("editor/" + sessionId + "/Event/Get").queryParam("name", "Hello")
+ .queryParam("version", (String) null).request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+ result = target("editor/" + sessionId + "/Event/Get").queryParam("name", "IDontExist")
+ .queryParam("version", (String) null).request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = target("editor/-123345/Event/Get").queryParam("name", (String) null)
+ .queryParam("version", (String) null).request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ result = target("editor/123345/Event/Get").queryParam("name", (String) null)
+ .queryParam("version", (String) null).request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ try {
+ target("editor/" + corruptSessionId + "/Event/Get").queryParam("name", "Hello")
+ .queryParam("version", (String) null).request().get(ApexAPIResult.class);
+ } catch (final Exception e) {
+ assertEquals("HTTP 500 Request failed.", e.getMessage());
+ }
+
+ result = target("editor/" + sessionId + "/Validate/Event").queryParam("name", (String) null)
+ .queryParam("version", (String) null).request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+ result = target("editor/-12345/Validate/Event").queryParam("name", (String) null)
+ .queryParam("version", (String) null).request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ result = target("editor/12345/Validate/Event").queryParam("name", (String) null)
+ .queryParam("version", (String) null).request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ try {
+ target("editor/" + corruptSessionId + "/Event/Delete").queryParam("name", (String) null)
+ .queryParam("version", (String) null).request().delete(ApexAPIResult.class);
+ } catch (final Exception e) {
+ assertEquals("HTTP 500 Request failed.", e.getMessage());
+ }
+
+ result = target("editor/-123345/Event/Delete").queryParam("name", (String) null)
+ .queryParam("version", (String) null).request().delete(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ result = target("editor/123345/Event/Delete").queryParam("name", (String) null)
+ .queryParam("version", (String) null).request().delete(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ result = target("editor/" + sessionId + "/Event/Delete").queryParam("name", "Hello")
+ .queryParam("version", "0.0.2").request().delete(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+ result = target("editor/" + sessionId + "/Event/Delete").queryParam("name", (String) null)
+ .queryParam("version", (String) null).request().delete(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+ }
+
+ @Test
+ public void testTask() throws IOException {
+ final int corruptSessionId = ApexEditorRestResource.createCorruptSession();
+
+ ApexAPIResult result = target("editor/-1/Session/Create").request().get(ApexAPIResult.class);
+ assertEquals(RESULT.SUCCESS, result.getResult());
+ final int sessionId = new Integer(result.getMessages().get(0));
+
+ result = target("editor/-12345/Validate/Task").request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ result = target("editor/" + sessionId + "/Validate/Task").request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ try {
+ target("editor/" + corruptSessionId + "/Validate/Task").request().get(ApexAPIResult.class);
+ } catch (final Exception e) {
+ assertEquals("HTTP 500 Request failed.", e.getMessage());
+ }
+
+ result = target("editor/" + sessionId + "/Validate/Task").queryParam("name", (String) null)
+ .queryParam("version", (String) null).request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ result = target("editor/" + sessionId + "/Validate/Task").queryParam("name", "%%%$£")
+ .queryParam("version", (String) null).request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ final String modelString = TextFileUtils.getTextFileAsString("src/test/resources/models/PolicyModel.json");
+
+ Entity<String> modelEntity = Entity.entity("Somewhere over the rainbow", MediaType.APPLICATION_JSON);
+ result = target("editor/" + -12345 + "/Model/Load").request().put(modelEntity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ result = target("editor/" + 12345 + "/Model/Load").request().put(modelEntity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ result = target("editor/" + sessionId + "/Model/Load").request().put(modelEntity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ modelEntity = Entity.entity("", MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Model/Load").request().put(modelEntity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ modelEntity = Entity.entity(modelString, MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Model/Load").request().put(modelEntity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+ result = target("editor/" + sessionId + "/Event/Get").queryParam("name", (String) null)
+ .queryParam("version", (String) null).request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ String entityString = "{" + "\"name\" : \"Hello\"," + "\"version\" : \"0.0.2\","
+ + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ Entity<String> entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/-12345/Task/Create").request().post(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ result = target("editor/1234545/Task/Create").request().post(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ result = target("editor/" + sessionId + "/Task/Create").request().post(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+ result = target("editor/" + sessionId + "/Task/Create").request().post(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.CONCEPT_EXISTS, result.getResult());
+
+ try {
+ target("editor/" + corruptSessionId + "/Task/Create").request().post(entity, ApexAPIResult.class);
+ } catch (final Exception e) {
+ assertEquals("HTTP 500 Request failed.", e.getMessage());
+ }
+
+ entityString = "{" + "\"name\" : \"Hiya\"," + "\"version\" : \"0.0.2\","
+ + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002799\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Task/Create").request().post(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ entityString = "{" + "\"name\" : \"HowsItGoing\"," + "\"version\" : \"0.0.2\","
+ + "\"inputFields\" : {\"IField0\" : {\"name\" : \"StringType\", \"version\" : \"0.0.1\", \"localName\" : \"IField0\", \"optional\" : false}},"
+ + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002799\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Task/Create").request().post(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ entityString = "{" + "\"name\" : \"Hi\"," + "\"version\" : \"0.0.2\","
+ + "\"inputFields\" : {\"IField0\" : null},"
+ + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002799\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Task/Create").request().post(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ entityString = "{" + "\"name\" : \"GoodDay\"," + "\"version\" : \"0.0.2\","
+ + "\"inputFields\" : {\"IField0\" : {\"name\" : \"NonExistantType\", \"version\" : \"0.0.1\", \"localName\" : \"IField0\", \"optional\" : false}},"
+ + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002799\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Task/Create").request().post(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ entityString = "{" + "\"name\" : \"Howdy\"," + "\"version\" : \"0.0.2\","
+ + "\"inputFields\" : {\"IField0\" : {\"name\" : \"NonExistantType\", \"version\" : \"0.0.1\", \"localName\" : \"NotIField0\", \"optional\" : false}},"
+ + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002799\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Task/Create").request().post(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ entityString = "{" + "\"name\" : \"HowsItGoing2\"," + "\"version\" : \"0.0.2\","
+ + "\"outputFields\" : {\"OField0\" : {\"name\" : \"StringType\", \"version\" : \"0.0.1\", \"localName\" : \"OField0\", \"optional\" : false}},"
+ + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002799\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Task/Create").request().post(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ entityString = "{" + "\"name\" : \"Hi2\"," + "\"version\" : \"0.0.2\","
+ + "\"outputFields\" : {\"OField0\" : null},"
+ + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002799\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Task/Create").request().post(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ entityString = "{" + "\"name\" : \"GoodDay2\"," + "\"version\" : \"0.0.2\","
+ + "\"outputFields\" : {\"OField0\" : {\"name\" : \"NonExistantType\", \"version\" : \"0.0.1\", \"localName\" : \"OField0\", \"optional\" : false}},"
+ + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002799\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Task/Create").request().post(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ entityString = "{" + "\"name\" : \"Howdy2\"," + "\"version\" : \"0.0.2\","
+ + "\"outputFields\" : {\"OField0\" : {\"name\" : \"NonExistantType\", \"version\" : \"0.0.1\", \"localName\" : \"NotOField0\", \"optional\" : false}},"
+ + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002799\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Task/Create").request().post(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ entityString = "{" + "\"name\" : \"HowsItGoing3\"," + "\"version\" : \"0.0.2\","
+ + "\"taskLogic\" : {\"logicFlavour\" : \"LemonAndLime\", \"logic\" : \"lots of lemons, lots of lime\"},"
+ + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002799\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Task/Create").request().post(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ entityString = "{" + "\"name\" : \"Hi3\"," + "\"version\" : \"0.0.2\","
+ + "\"taskLogic\" : null," + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002799\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Task/Create").request().post(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ entityString = "{" + "\"name\" : \"GoodDay3\"," + "\"version\" : \"0.0.2\","
+ + "\"namespace\" : \"somewhere.over.the.rainbow\"," + "\"source\" : \"beginning\","
+ + "\"target\" : \"end\","
+ + "\"taskLogic\" : {\"logicFlavour\" : \"UNDEFINED\", \"logic\" : \"lots of lemons, lots of lime\"},"
+ + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002799\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Task/Create").request().post(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ entityString = "{" + "\"name\" : \"Howdy3\"," + "\"version\" : \"0.0.2\","
+ + "\"taskLogic\" : {\"logicFlavour\" : \"LemonAndLime\", \"logic\" : null},"
+ + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002799\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Task/Create").request().post(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ entityString = "{" + "\"name\" : \"HowsItGoing4\"," + "\"version\" : \"0.0.2\","
+ + "\"parameters\" : {\"Par0\" : {\"parameterName\" : \"Par0\", \"defaultValue\" : \"Parameter Defaultvalue\"}},"
+ + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002799\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Task/Create").request().post(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ entityString = "{" + "\"name\" : \"Hi4\"," + "\"version\" : \"0.0.2\","
+ + "\"parameters\" : {\"Par0\" : null},"
+ + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002799\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Task/Create").request().post(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ entityString = "{" + "\"name\" : \"GoodDay4\"," + "\"version\" : \"0.0.2\","
+ + "\"parameters\" : {\"Par0\" : {\"parameterName\" : \"NotPar0\", \"defaultValue\" : \"Parameter Defaultvalue\"}},"
+ + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002799\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Task/Create").request().post(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ entityString = "{" + "\"name\" : \"Howdy4\"," + "\"version\" : \"0.0.2\","
+ + "\"parameters\" : {\"Par0\" : {\"parameterName\" : \"MyParameter\", \"defaultValue\" : null}},"
+ + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002799\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Task/Create").request().post(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ entityString = "{" + "\"name\" : \"HowsItGoing5\"," + "\"version\" : \"0.0.2\","
+ + "\"contexts\" : [{\"name\" : \"contextAlbum0\", \"version\" : \"0.0.1\"}],"
+ + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002799\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Task/Create").request().post(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ entityString = "{" + "\"name\" : \"Hi5\"," + "\"version\" : \"0.0.2\","
+ + "\"contexts\" : []," + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002799\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Task/Create").request().post(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ entityString = "{" + "\"name\" : \"GoodDay5\"," + "\"version\" : \"0.0.2\","
+ + "\"contexts\" : [{\"name\" : \"NonExistantType\", \"version\" : \"0.0.1\"}],"
+ + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002799\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Task/Create").request().post(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ entityString = "{" + "\"name\" : \"Howdy5\"," + "\"version\" : \"0.0.2\","
+ + "\"contexts\" : [{\"name\" : null, \"version\" : \"0.0.1\"}],"
+ + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002799\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Task/Create").request().post(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ entityString = "{" + "\"name\" : \"Hello\"," + "\"version\" : \"0.0.2\","
+ + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/-12345/Task/Update").request().put(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ result = target("editor/1234545/Task/Update").request().put(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ result = target("editor/" + sessionId + "/Task/Update").request().put(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ try {
+ target("editor/" + corruptSessionId + "/Task/Update").request().put(entity, ApexAPIResult.class);
+ } catch (final Exception e) {
+ assertEquals("HTTP 500 Request failed.", e.getMessage());
+ }
+
+ entityString = "{" + "\"name\" : null," + "\"version\" : \"0.0.2\","
+ + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Task/Update").request().put(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ entityString = "{" + "\"name\" : \"NonExistantEvent\"," + "\"version\" : \"0.0.2\","
+ + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Task/Update").request().put(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = target("editor/" + sessionId + "/Task/Get").queryParam("name", "Hello")
+ .queryParam("version", (String) null).request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+ result = target("editor/" + sessionId + "/Task/Get").queryParam("name", (String) null)
+ .queryParam("version", (String) null).request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+ result = target("editor/" + sessionId + "/Task/Get").queryParam("name", "IDontExist")
+ .queryParam("version", (String) null).request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = target("editor/-123345/Task/Get").queryParam("name", (String) null)
+ .queryParam("version", (String) null).request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ result = target("editor/123345/Task/Get").queryParam("name", (String) null).queryParam("version", (String) null)
+ .request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ try {
+ target("editor/" + corruptSessionId + "/Task/Get").queryParam("name", "Hello")
+ .queryParam("version", (String) null).request().get(ApexAPIResult.class);
+ } catch (final Exception e) {
+ assertEquals("HTTP 500 Request failed.", e.getMessage());
+ }
+
+ result = target("editor/" + sessionId + "/Validate/Event").queryParam("name", (String) null)
+ .queryParam("version", (String) null).request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+ result = target("editor/-12345/Validate/Event").queryParam("name", (String) null)
+ .queryParam("version", (String) null).request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ result = target("editor/12345/Validate/Event").queryParam("name", (String) null)
+ .queryParam("version", (String) null).request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ try {
+ target("editor/" + corruptSessionId + "/Task/Delete").queryParam("name", (String) null)
+ .queryParam("version", (String) null).request().delete(ApexAPIResult.class);
+ } catch (final Exception e) {
+ assertEquals("HTTP 500 Request failed.", e.getMessage());
+ }
+
+ result = target("editor/-123345/Task/Delete").queryParam("name", (String) null)
+ .queryParam("version", (String) null).request().delete(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ result = target("editor/123345/Task/Delete").queryParam("name", (String) null)
+ .queryParam("version", (String) null).request().delete(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ result = target("editor/" + sessionId + "/Task/Delete").queryParam("name", "Hello")
+ .queryParam("version", "0.0.2").request().delete(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+ result = target("editor/" + sessionId + "/Task/Delete").queryParam("name", (String) null)
+ .queryParam("version", (String) null).request().delete(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+ }
+
+ @Test
+ public void testPolicy() throws IOException {
+ final int corruptSessionId = ApexEditorRestResource.createCorruptSession();
+
+ ApexAPIResult result = target("editor/-1/Session/Create").request().get(ApexAPIResult.class);
+ assertEquals(RESULT.SUCCESS, result.getResult());
+ final int sessionId = new Integer(result.getMessages().get(0));
+
+ result = target("editor/-12345/Model/Validate").request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ result = target("editor/" + sessionId + "/Model/Validate").request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ try {
+ target("editor/" + corruptSessionId + "/Model/Validate").request().get(ApexAPIResult.class);
+ } catch (final Exception e) {
+ assertEquals("HTTP 500 Request failed.", e.getMessage());
+ }
+
+ result = target("editor/" + sessionId + "/Model/Validate").queryParam("name", (String) null)
+ .queryParam("version", (String) null).request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ result = target("editor/" + sessionId + "/Model/Validate").queryParam("name", "%%%$£")
+ .queryParam("version", (String) null).request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ final String modelString = TextFileUtils.getTextFileAsString("src/test/resources/models/PolicyModel.json");
+
+ Entity<String> modelEntity = Entity.entity("Somewhere over the rainbow", MediaType.APPLICATION_JSON);
+ result = target("editor/" + -12345 + "/Model/Load").request().put(modelEntity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ result = target("editor/" + 12345 + "/Model/Load").request().put(modelEntity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ result = target("editor/" + sessionId + "/Model/Load").request().put(modelEntity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ modelEntity = Entity.entity("", MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Model/Load").request().put(modelEntity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ modelEntity = Entity.entity(modelString, MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Model/Load").request().put(modelEntity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+ result = target("editor/" + sessionId + "/Event/Get").queryParam("name", (String) null)
+ .queryParam("version", (String) null).request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ String entityString = "{" + "\"name\" : \"Hello\"," + "\"version\" : \"0.0.2\","
+ + "\"template\" : \"somewhere.over.the.rainbow\"," + "\"firstState\" : \"state\","
+ + "\"states\" : {" + " \"state\" : {" + " \"name\" : \"state\","
+ + " \"trigger\" : {\"name\" : \"inEvent\", \"version\" : \"0.0.1\"},"
+ + " \"defaultTask\" : {\"name\" : \"task\", \"version\" : \"0.0.1\"}," + " \"stateOutputs\" : {"
+ + " \"so0\" : {"
+ + " \"event\" : {\"name\" : \"inEvent\", \"version\" : \"0.0.1\"},"
+ + " \"nextState\" : null" + " }" + " }," + " \"tasks\" : {"
+ + " \"tr0\" : {" + " \"task\" : {\"name\" : \"task\", \"version\" : \"0.0.1\"},"
+ + " \"outputType\" : \"DIRECT\"," + " \"outputName\" : \"so0\"" + " }" + " }" + " }" + "},"
+ + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ Entity<String> entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/-12345/Policy/Create").request().post(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ result = target("editor/1234545/Policy/Create").request().post(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ result = target("editor/" + sessionId + "/Policy/Create").request().post(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+ result = target("editor/" + sessionId + "/Policy/Create").request().post(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.CONCEPT_EXISTS, result.getResult());
+
+ try {
+ target("editor/" + corruptSessionId + "/Policy/Create").request().post(entity, ApexAPIResult.class);
+ } catch (final Exception e) {
+ assertEquals("HTTP 500 Request failed.", e.getMessage());
+ }
+
+ entityString = "{" + "\"name\" : \"GoodTaSeeYa\"," + "\"version\" : \"0.0.2\","
+ + "\"template\" : \"somewhere.over.the.rainbow\"," + "\"firstState\" : \"state\","
+ + "\"states\" : null," + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Policy/Create").request().post(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ entityString = "{" + "\"name\" : \"HelloAnother\"," + "\"version\" : \"0.0.2\","
+ + "\"template\" : \"somewhere.over.the.rainbow\"," + "\"firstState\" : \"state\","
+ + "\"states\" : {" + " \"state\" : {" + " \"name\" : \"state\","
+ + " \"trigger\" : {\"name\" : \"inEvent\", \"version\" : \"0.0.1\"},"
+ + " \"defaultTask\" : {\"name\" : \"task\", \"version\" : \"0.0.1\"}," + " \"stateOutputs\" : {"
+ + " \"so0\" : {"
+ + " \"event\" : {\"name\" : \"inEvent\", \"version\" : \"0.0.1\"},"
+ + " \"nextState\" : null" + " }" + " }," + " \"tasks\" : {"
+ + " \"tr0\" : {" + " \"task\" : {\"name\" : \"task\", \"version\" : \"0.0.1\"},"
+ + " \"outputType\" : \"DIRECT\"," + " \"outputName\" : \"so0\"" + " }" + " }" + " }" + "},"
+ + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Policy/Create").request().post(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ entityString = "{" + "\"name\" : \"Hello2\"," + "\"version\" : \"0.0.2\","
+ + "\"template\" : \"somewhere.over.the.rainbow\"," + "\"firstState\" : \"state\","
+ + "\"states\" : {" + " \"state\" : {" + " \"name\" : \"state\","
+ + " \"trigger\" : null,"
+ + " \"defaultTask\" : {\"name\" : \"task\", \"version\" : \"0.0.1\"}," + " \"stateOutputs\" : {"
+ + " \"so0\" : {"
+ + " \"event\" : {\"name\" : \"inEvent\", \"version\" : \"0.0.1\"},"
+ + " \"nextState\" : null" + " }" + " }," + " \"tasks\" : {"
+ + " \"tr0\" : {" + " \"task\" : {\"name\" : \"task\", \"version\" : \"0.0.1\"},"
+ + " \"outputType\" : \"DIRECT\"," + " \"outputName\" : \"so0\"" + " }" + " }" + " }" + "},"
+ + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Policy/Create").request().post(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ entityString = "{" + "\"name\" : \"Hello3\"," + "\"version\" : \"0.0.2\","
+ + "\"template\" : \"somewhere.over.the.rainbow\"," + "\"firstState\" : \"state\","
+ + "\"states\" : {" + " \"state\" : {" + " \"name\" : \"state\","
+ + " \"trigger\" : {\"name\" : \"inEvent\", \"version\" : \"0.0.1\"},"
+ + " \"defaultTask\" : null," + " \"stateOutputs\" : {" + " \"so0\" : {"
+ + " \"event\" : {\"name\" : \"inEvent\", \"version\" : \"0.0.1\"},"
+ + " \"nextState\" : null" + " }" + " }," + " \"tasks\" : {"
+ + " \"tr0\" : {" + " \"task\" : {\"name\" : \"task\", \"version\" : \"0.0.1\"},"
+ + " \"outputType\" : \"DIRECT\"," + " \"outputName\" : \"so0\"" + " }" + " }" + " }" + "},"
+ + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Policy/Create").request().post(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ entityString = "{" + "\"name\" : \"Hello4\"," + "\"version\" : \"0.0.2\","
+ + "\"template\" : \"somewhere.over.the.rainbow\"," + "\"firstState\" : \"state\","
+ + "\"states\" : {" + " \"state\" : {" + " \"name\" : \"state\","
+ + " \"trigger\" : {\"name\" : \"inEvent\", \"version\" : \"0.0.1\"},"
+ + " \"defaultTask\" : {\"name\" : \"task\", \"version\" : \"0.0.1\"},"
+ + " \"stateOutputs\" : null," + " \"tasks\" : {" + " \"tr0\" : {"
+ + " \"task\" : {\"name\" : \"task\", \"version\" : \"0.0.1\"},"
+ + " \"outputType\" : \"DIRECT\"," + " \"outputName\" : \"so0\"" + " }" + " }" + " }" + "},"
+ + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Policy/Create").request().post(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ entityString = "{" + "\"name\" : \"Hello5\"," + "\"version\" : \"0.0.2\","
+ + "\"template\" : \"somewhere.over.the.rainbow\"," + "\"firstState\" : \"state\","
+ + "\"states\" : {" + " \"state\" : {" + " \"name\" : \"state\","
+ + " \"trigger\" : {\"name\" : \"inEvent\", \"version\" : \"0.0.1\"},"
+ + " \"defaultTask\" : {\"name\" : \"task\", \"version\" : \"0.0.1\"}," + " \"stateOutputs\" : {"
+ + " \"so0\" : {"
+ + " \"event\" : {\"name\" : \"inEvent\", \"version\" : \"0.0.1\"},"
+ + " \"nextState\" : null" + " }" + " }," + " \"tasks\" : null" + " }" + "},"
+ + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Policy/Create").request().post(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ entityString = "{" + "\"name\" : \"Hello6\"," + "\"version\" : \"0.0.2\","
+ + "\"template\" : \"somewhere.over.the.rainbow\"," + "\"firstState\" : \"state\","
+ + "\"states\" : {" + " \"state\" : {" + " \"name\" : \"state\","
+ + " \"trigger\" : {\"name\" : \"IDontExist\", \"version\" : \"0.0.1\"},"
+ + " \"defaultTask\" : {\"name\" : \"task\", \"version\" : \"0.0.1\"}," + " \"stateOutputs\" : {"
+ + " \"so0\" : {"
+ + " \"event\" : {\"name\" : \"inEvent\", \"version\" : \"0.0.1\"},"
+ + " \"nextState\" : null" + " }" + " }," + " \"tasks\" : {"
+ + " \"tr0\" : {" + " \"task\" : {\"name\" : \"task\", \"version\" : \"0.0.1\"},"
+ + " \"outputType\" : \"DIRECT\"," + " \"outputName\" : \"so0\"" + " }" + " }" + " }" + "},"
+ + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Policy/Create").request().post(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ entityString = "{" + "\"name\" : \"Hello7\"," + "\"version\" : \"0.0.2\","
+ + "\"template\" : \"somewhere.over.the.rainbow\"," + "\"firstState\" : \"state\","
+ + "\"states\" : {" + " \"state\" : null" + "},"
+ + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Policy/Create").request().post(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ entityString = "{" + "\"name\" : \"Hello8\"," + "\"version\" : \"0.0.2\","
+ + "\"template\" : \"somewhere.over.the.rainbow\"," + "\"firstState\" : \"state\","
+ + "\"states\" : {" + " \"state\" : {" + " \"name\" : \"state\","
+ + " \"trigger\" : {\"name\" : \"inEvent\", \"version\" : \"0.0.1\"},"
+ + " \"defaultTask\" : {\"name\" : \"task\", \"version\" : \"0.0.1\"}," + " \"stateOutputs\" : {"
+ + " \"so0\" : {"
+ + " \"event\" : {\"name\" : \"IDontExist\", \"version\" : \"0.0.1\"},"
+ + " \"nextState\" : null" + " }" + " }," + " \"tasks\" : {"
+ + " \"tr0\" : {" + " \"task\" : {\"name\" : \"task\", \"version\" : \"0.0.1\"},"
+ + " \"outputType\" : \"DIRECT\"," + " \"outputName\" : \"so0\"" + " }" + " }" + " }" + "},"
+ + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Policy/Create").request().post(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ entityString = "{" + "\"name\" : \"Hello9\"," + "\"version\" : \"0.0.2\","
+ + "\"template\" : \"somewhere.over.the.rainbow\"," + "\"firstState\" : \"state\","
+ + "\"states\" : {" + " \"state\" : {" + " \"name\" : \"state\","
+ + " \"trigger\" : {\"name\" : \"inEvent\", \"version\" : \"0.0.1\"},"
+ + " \"defaultTask\" : {\"name\" : \"task\", \"version\" : \"0.0.1\"}," + " \"stateOutputs\" : {"
+ + " \"so0\" : {" + " \"event\" : null," + " \"nextState\" : null" + " }"
+ + " }," + " \"tasks\" : {" + " \"tr0\" : {"
+ + " \"task\" : {\"name\" : \"task\", \"version\" : \"0.0.1\"},"
+ + " \"outputType\" : \"DIRECT\"," + " \"outputName\" : \"so0\"" + " }" + " }" + " }" + "},"
+ + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Policy/Create").request().post(entity, ApexAPIResult.class);
+ System.err.println(result);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ entityString = "{" + "\"name\" : \"Hello10\"," + "\"version\" : \"0.0.2\","
+ + "\"template\" : \"somewhere.over.the.rainbow\"," + "\"firstState\" : \"state\","
+ + "\"states\" : {" + " \"state\" : {" + " \"name\" : \"state\","
+ + " \"trigger\" : {\"name\" : \"inEvent\", \"version\" : \"0.0.1\"},"
+ + " \"defaultTask\" : {\"name\" : \"task\", \"version\" : \"0.0.1\"}," + " \"stateOutputs\" : {"
+ + " \"so0\" : {"
+ + " \"event\" : {\"name\" : \"inEvent\", \"version\" : \"0.0.1\"},"
+ + " \"nextState\" : null" + " }" + " }," + " \"tasks\" : {"
+ + " \"tr0\" : {"
+ + " \"task\" : {\"name\" : \"IDontExist\", \"version\" : \"0.0.1\"},"
+ + " \"outputType\" : \"DIRECT\"," + " \"outputName\" : \"so0\"" + " }" + " }" + " }" + "},"
+ + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Policy/Create").request().post(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ entityString = "{" + "\"name\" : \"Hello11\"," + "\"version\" : \"0.0.2\","
+ + "\"template\" : \"somewhere.over.the.rainbow\"," + "\"firstState\" : \"state\","
+ + "\"states\" : {" + " \"state\" : {" + " \"name\" : \"state\","
+ + " \"trigger\" : {\"name\" : \"inEvent\", \"version\" : \"0.0.1\"},"
+ + " \"defaultTask\" : {\"name\" : \"task\", \"version\" : \"0.0.1\"}," + " \"stateOutputs\" : {"
+ + " \"so0\" : {"
+ + " \"event\" : {\"name\" : \"inEvent\", \"version\" : \"0.0.1\"},"
+ + " \"nextState\" : null" + " }" + " }," + " \"tasks\" : {"
+ + " \"tr0\" : {" + " \"task\" : null," + " \"outputType\" : \"DIRECT\","
+ + " \"outputName\" : \"so0\"" + " }" + " }" + " }" + "},"
+ + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Policy/Create").request().post(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ entityString = "{" + "\"name\" : \"Hello12\"," + "\"version\" : \"0.0.2\","
+ + "\"template\" : \"somewhere.over.the.rainbow\"," + "\"firstState\" : \"state\","
+ + "\"states\" : {" + " \"state\" : {"
+ + " \"name\" : \"state\","
+ + " \"trigger\" : {\"name\" : \"inEvent\", \"version\" : \"0.0.1\"},"
+ + " \"defaultTask\" : {\"name\" : \"task\", \"version\" : \"0.0.1\"},"
+ + " \"taskSelectionLogic\" : {\"logicFlavour\" : \"LemonAndLime\", \"logic\" : \"lots of lemons, lots of lime\"},"
+ + " \"stateOutputs\" : {" + " \"so0\" : {"
+ + " \"event\" : {\"name\" : \"inEvent\", \"version\" : \"0.0.1\"},"
+ + " \"nextState\" : null" + " }" + " }," + " \"tasks\" : {"
+ + " \"tr0\" : {"
+ + " \"task\" : {\"name\" : \"task\", \"version\" : \"0.0.1\"},"
+ + " \"outputType\" : \"DIRECT\"," + " \"outputName\" : \"so0\"" + " }" + " }"
+ + " }" + "}," + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Policy/Create").request().post(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ entityString = "{" + "\"name\" : \"Hello13\"," + "\"version\" : \"0.0.2\","
+ + "\"template\" : \"somewhere.over.the.rainbow\"," + "\"firstState\" : \"state\","
+ + "\"states\" : {" + " \"state\" : {"
+ + " \"name\" : \"state\","
+ + " \"trigger\" : {\"name\" : \"inEvent\", \"version\" : \"0.0.1\"},"
+ + " \"defaultTask\" : {\"name\" : \"task\", \"version\" : \"0.0.1\"},"
+ + " \"taskSelectionLogic\" : {\"logicFlavour\" : \"LemonAndLime\", \"logic\" : null},"
+ + " \"stateOutputs\" : {" + " \"so0\" : {"
+ + " \"event\" : {\"name\" : \"inEvent\", \"version\" : \"0.0.1\"},"
+ + " \"nextState\" : null" + " }" + " }," + " \"tasks\" : {"
+ + " \"tr0\" : {"
+ + " \"task\" : {\"name\" : \"task\", \"version\" : \"0.0.1\"},"
+ + " \"outputType\" : \"DIRECT\"," + " \"outputName\" : \"so0\"" + " }" + " }"
+ + " }" + "}," + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Policy/Create").request().post(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ entityString = "{" + "\"name\" : \"Hello14\"," + "\"version\" : \"0.0.2\","
+ + "\"template\" : \"somewhere.over.the.rainbow\"," + "\"firstState\" : \"state\","
+ + "\"states\" : {" + " \"state\" : {"
+ + " \"name\" : \"state\","
+ + " \"trigger\" : {\"name\" : \"inEvent\", \"version\" : \"0.0.1\"},"
+ + " \"defaultTask\" : {\"name\" : \"task\", \"version\" : \"0.0.1\"},"
+ + " \"taskSelectionLogic\" : {\"logicFlavour\" : \"LemonAndLime\", \"logic\" : \"lots of lemons, lots of lime\"},"
+ + " \"contexts\" : [{\"name\" : \"contextAlbum0\", \"version\" : \"0.0.1\"}],"
+ + " \"stateOutputs\" : {" + " \"so0\" : {"
+ + " \"event\" : {\"name\" : \"inEvent\", \"version\" : \"0.0.1\"},"
+ + " \"nextState\" : null" + " }" + " }," + " \"tasks\" : {"
+ + " \"tr0\" : {"
+ + " \"task\" : {\"name\" : \"task\", \"version\" : \"0.0.1\"},"
+ + " \"outputType\" : \"DIRECT\"," + " \"outputName\" : \"so0\"" + " }" + " }"
+ + " }" + "}," + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Policy/Create").request().post(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ entityString = "{" + "\"name\" : \"Hello15\"," + "\"version\" : \"0.0.2\","
+ + "\"template\" : \"somewhere.over.the.rainbow\"," + "\"firstState\" : \"state\","
+ + "\"states\" : {" + " \"state\" : {"
+ + " \"name\" : \"state\","
+ + " \"trigger\" : {\"name\" : \"inEvent\", \"version\" : \"0.0.1\"},"
+ + " \"defaultTask\" : {\"name\" : \"task\", \"version\" : \"0.0.1\"},"
+ + " \"taskSelectionLogic\" : {\"logicFlavour\" : \"LemonAndLime\", \"logic\" : \"lots of lemons, lots of lime\"},"
+ + " \"contexts\" : [{\"name\" : \"IDontExist\", \"version\" : \"0.0.1\"}],"
+ + " \"stateOutputs\" : {" + " \"so0\" : {"
+ + " \"event\" : {\"name\" : \"inEvent\", \"version\" : \"0.0.1\"},"
+ + " \"nextState\" : null" + " }" + " }," + " \"tasks\" : {"
+ + " \"tr0\" : {"
+ + " \"task\" : {\"name\" : \"task\", \"version\" : \"0.0.1\"},"
+ + " \"outputType\" : \"DIRECT\"," + " \"outputName\" : \"so0\"" + " }" + " }"
+ + " }" + "}," + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Policy/Create").request().post(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ entityString = "{" + "\"name\" : \"Hello16\"," + "\"version\" : \"0.0.2\","
+ + "\"template\" : \"somewhere.over.the.rainbow\"," + "\"firstState\" : \"state\","
+ + "\"states\" : {" + " \"state\" : {"
+ + " \"name\" : \"state\","
+ + " \"trigger\" : {\"name\" : \"inEvent\", \"version\" : \"0.0.1\"},"
+ + " \"defaultTask\" : {\"name\" : \"task\", \"version\" : \"0.0.1\"},"
+ + " \"taskSelectionLogic\" : {\"logicFlavour\" : \"LemonAndLime\", \"logic\" : \"lots of lemons, lots of lime\"},"
+ + " \"contexts\" : [null]," + " \"stateOutputs\" : {" + " \"so0\" : {"
+ + " \"event\" : {\"name\" : \"inEvent\", \"version\" : \"0.0.1\"},"
+ + " \"nextState\" : null" + " }" + " }," + " \"tasks\" : {"
+ + " \"tr0\" : {"
+ + " \"task\" : {\"name\" : \"task\", \"version\" : \"0.0.1\"},"
+ + " \"outputType\" : \"DIRECT\"," + " \"outputName\" : \"so0\"" + " }" + " }"
+ + " }" + "}," + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Policy/Create").request().post(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ entityString = "{" + "\"name\" : \"Hello17\"," + "\"version\" : \"0.0.2\","
+ + "\"template\" : \"somewhere.over.the.rainbow\"," + "\"firstState\" : \"state\","
+ + "\"states\" : {" + " \"state\" : {"
+ + " \"name\" : \"state\","
+ + " \"trigger\" : {\"name\" : \"inEvent\", \"version\" : \"0.0.1\"},"
+ + " \"defaultTask\" : {\"name\" : \"task\", \"version\" : \"0.0.1\"},"
+ + " \"taskSelectionLogic\" : {\"logicFlavour\" : \"LemonAndLime\", \"logic\" : \"lots of lemons, lots of lime\"},"
+ + " \"contexts\" : [{\"name\" : \"contextAlbum0\", \"version\" : \"0.0.1\"}],"
+ + " \"stateOutputs\" : {" + " \"so0\" : {"
+ + " \"event\" : {\"name\" : \"inEvent\", \"version\" : \"0.0.1\"},"
+ + " \"nextState\" : null" + " }" + " }," + " \"tasks\" : {"
+ + " \"tr0\" : {"
+ + " \"task\" : {\"name\" : \"task\", \"version\" : \"0.0.1\"},"
+ + " \"outputType\" : \"DIRECT\"," + " \"outputName\" : \"so0\"" + " }" + " },"
+ + " \"finalizers\" : {"
+ + " \"sf0\" : {\"logicFlavour\" : \"LemonAndLime\", \"logic\" : \"lots of lemons, lots of lime\"}"
+ + " }" + " }" + "}," + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Policy/Create").request().post(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ entityString = "{" + "\"name\" : \"Hello18\"," + "\"version\" : \"0.0.2\","
+ + "\"template\" : \"somewhere.over.the.rainbow\"," + "\"firstState\" : \"state\","
+ + "\"states\" : {" + " \"state\" : {"
+ + " \"name\" : \"state\","
+ + " \"trigger\" : {\"name\" : \"inEvent\", \"version\" : \"0.0.1\"},"
+ + " \"defaultTask\" : {\"name\" : \"task\", \"version\" : \"0.0.1\"},"
+ + " \"taskSelectionLogic\" : {\"logicFlavour\" : \"LemonAndLime\", \"logic\" : \"lots of lemons, lots of lime\"},"
+ + " \"contexts\" : [{\"name\" : \"contextAlbum0\", \"version\" : \"0.0.1\"}],"
+ + " \"stateOutputs\" : {" + " \"so0\" : {"
+ + " \"event\" : {\"name\" : \"inEvent\", \"version\" : \"0.0.1\"},"
+ + " \"nextState\" : null" + " }" + " }," + " \"tasks\" : {"
+ + " \"tr0\" : {"
+ + " \"task\" : {\"name\" : \"task\", \"version\" : \"0.0.1\"},"
+ + " \"outputType\" : \"DIRECT\"," + " \"outputName\" : \"so0\"" + " }" + " },"
+ + " \"finalizers\" : {" + " \"sf0\" : null" + " }" + " }" + "},"
+ + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Policy/Create").request().post(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ entityString = "{" + "\"name\" : \"Hello19\"," + "\"version\" : \"0.0.2\","
+ + "\"template\" : \"somewhere.over.the.rainbow\"," + "\"firstState\" : \"state\","
+ + "\"states\" : {" + " \"state\" : {"
+ + " \"name\" : \"state\","
+ + " \"trigger\" : {\"name\" : \"inEvent\", \"version\" : \"0.0.1\"},"
+ + " \"defaultTask\" : {\"name\" : \"task\", \"version\" : \"0.0.1\"},"
+ + " \"taskSelectionLogic\" : {\"logicFlavour\" : \"LemonAndLime\", \"logic\" : \"lots of lemons, lots of lime\"},"
+ + " \"contexts\" : [{\"name\" : \"contextAlbum0\", \"version\" : \"0.0.1\"}],"
+ + " \"stateOutputs\" : {" + " \"so0\" : {"
+ + " \"event\" : {\"name\" : \"inEvent\", \"version\" : \"0.0.1\"},"
+ + " \"nextState\" : null" + " }" + " }," + " \"tasks\" : {"
+ + " \"tr0\" : {"
+ + " \"task\" : {\"name\" : \"task\", \"version\" : \"0.0.1\"},"
+ + " \"outputType\" : \"DIRECT\"," + " \"outputName\" : \"so0\"" + " }" + " },"
+ + " \"finalizers\" : {"
+ + " \"sf0\" : {\"logicFlavour\" : \"LemonAndLime\", \"logic\" : null}" + " }" + " }"
+ + "}," + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ + "\"description\" : \"A description of hello\"" + "}";
+ entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Policy/Create").request().post(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ entityString = "{" + "\"name\" : \"HelloAnother\"," + "\"version\" : \"0.0.2\","
+ + "\"template\" : \"somewhere.over.the.rainbow\"," + "\"firstState\" : \"state\","
+ + "\"states\" : {" + " \"state\" : {" + " \"name\" : \"state\","
+ + " \"trigger\" : {\"name\" : \"inEvent\", \"version\" : \"0.0.1\"},"
+ + " \"defaultTask\" : {\"name\" : \"task\", \"version\" : \"0.0.1\"}," + " \"stateOutputs\" : {"
+ + " \"so0\" : {"
+ + " \"event\" : {\"name\" : \"inEvent\", \"version\" : \"0.0.1\"},"
+ + " \"nextState\" : null" + " }" + " }," + " \"tasks\" : {"
+ + " \"tr0\" : {" + " \"task\" : {\"name\" : \"task\", \"version\" : \"0.0.1\"},"
+ + " \"outputType\" : \"DIRECT\"," + " \"outputName\" : \"so0\"" + " }" + " }" + " }" + "},"
+ + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ + "\"description\" : \"A better description of hello\"" + "}";
+ entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/-12345/Policy/Update").request().put(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ result = target("editor/1234545/Policy/Update").request().put(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ result = target("editor/" + sessionId + "/Policy/Update").request().put(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ result = target("editor/" + sessionId + "/Policy/Update").queryParam("firstStatePeriodic", "true").request()
+ .put(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ try {
+ target("editor/" + corruptSessionId + "/Policy/Update").request().put(entity, ApexAPIResult.class);
+ } catch (final Exception e) {
+ assertEquals("HTTP 500 Request failed.", e.getMessage());
+ }
+
+ entityString = "{" + "\"name\" : null," + "\"version\" : \"0.0.2\","
+ + "\"template\" : \"somewhere.over.the.rainbow\"," + "\"firstState\" : \"state\","
+ + "\"states\" : {" + " \"state\" : {" + " \"name\" : \"state\","
+ + " \"trigger\" : {\"name\" : \"inEvent\", \"version\" : \"0.0.1\"},"
+ + " \"defaultTask\" : {\"name\" : \"task\", \"version\" : \"0.0.1\"}," + " \"stateOutputs\" : {"
+ + " \"so0\" : {"
+ + " \"event\" : {\"name\" : \"inEvent\", \"version\" : \"0.0.1\"},"
+ + " \"nextState\" : null" + " }" + " }," + " \"tasks\" : {"
+ + " \"tr0\" : {" + " \"task\" : {\"name\" : \"task\", \"version\" : \"0.0.1\"},"
+ + " \"outputType\" : \"DIRECT\"," + " \"outputName\" : \"so0\"" + " }" + " }" + " }" + "},"
+ + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ + "\"description\" : \"A better description of hello\"" + "}";
+ entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Policy/Update").request().put(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ entityString = "{" + "\"name\" : \"IDontExist\"," + "\"version\" : \"0.0.2\","
+ + "\"template\" : \"somewhere.over.the.rainbow\"," + "\"firstState\" : \"state\","
+ + "\"states\" : {" + " \"state\" : {" + " \"name\" : \"state\","
+ + " \"trigger\" : {\"name\" : \"inEvent\", \"version\" : \"0.0.1\"},"
+ + " \"defaultTask\" : {\"name\" : \"task\", \"version\" : \"0.0.1\"}," + " \"stateOutputs\" : {"
+ + " \"so0\" : {"
+ + " \"event\" : {\"name\" : \"inEvent\", \"version\" : \"0.0.1\"},"
+ + " \"nextState\" : null" + " }" + " }," + " \"tasks\" : {"
+ + " \"tr0\" : {" + " \"task\" : {\"name\" : \"task\", \"version\" : \"0.0.1\"},"
+ + " \"outputType\" : \"DIRECT\"," + " \"outputName\" : \"so0\"" + " }" + " }" + " }" + "},"
+ + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ + "\"description\" : \"A better description of hello\"" + "}";
+ entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
+ result = target("editor/" + sessionId + "/Policy/Update").request().put(entity, ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = target("editor/" + sessionId + "/Policy/Get").queryParam("name", "Hello")
+ .queryParam("version", (String) null).request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+ result = target("editor/" + sessionId + "/Policy/Get").queryParam("name", "IDontExist")
+ .queryParam("version", (String) null).request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = target("editor/" + sessionId + "/Policy/Get").queryParam("name", (String) null)
+ .queryParam("version", (String) null).request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+ result = target("editor/-123345/Policy/Get").queryParam("name", (String) null)
+ .queryParam("version", (String) null).request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ result = target("editor/123345/Policy/Get").queryParam("name", (String) null)
+ .queryParam("version", (String) null).request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ try {
+ target("editor/" + corruptSessionId + "/Policy/Get").queryParam("name", "Hello")
+ .queryParam("version", (String) null).request().get(ApexAPIResult.class);
+ } catch (final Exception e) {
+ assertEquals("HTTP 500 Request failed.", e.getMessage());
+ }
+
+ result = target("editor/" + sessionId + "/Validate/Event").queryParam("name", (String) null)
+ .queryParam("version", (String) null).request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+ result = target("editor/-12345/Validate/Event").queryParam("name", (String) null)
+ .queryParam("version", (String) null).request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ result = target("editor/12345/Validate/Event").queryParam("name", (String) null)
+ .queryParam("version", (String) null).request().get(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ try {
+ target("editor/" + corruptSessionId + "/Policy/Delete").queryParam("name", (String) null)
+ .queryParam("version", (String) null).request().delete(ApexAPIResult.class);
+ } catch (final Exception e) {
+ assertEquals("HTTP 500 Request failed.", e.getMessage());
+ }
+
+ result = target("editor/-123345/Policy/Delete").queryParam("name", (String) null)
+ .queryParam("version", (String) null).request().delete(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ result = target("editor/123345/Policy/Delete").queryParam("name", (String) null)
+ .queryParam("version", (String) null).request().delete(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ result = target("editor/" + sessionId + "/Policy/Delete").queryParam("name", "Hello")
+ .queryParam("version", "0.0.2").request().delete(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+ result = target("editor/" + sessionId + "/Policy/Delete").queryParam("name", (String) null)
+ .queryParam("version", (String) null).request().delete(ApexAPIResult.class);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+ }
+}
diff --git a/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/TestApexEditorStartup.java b/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/TestApexEditorStartup.java
new file mode 100644
index 000000000..0ae54e5af
--- /dev/null
+++ b/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/TestApexEditorStartup.java
@@ -0,0 +1,441 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.client.editor.rest;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+
+import org.junit.Test;
+import org.onap.policy.apex.client.editor.rest.ApexEditorMain.EditorState;
+
+/**
+ * The Class TestApexEditorStartup.
+ */
+public class TestApexEditorStartup {
+ // CHECKSTYLE:OFF: MagicNumber
+
+ /**
+ * Test no args.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ * @throws InterruptedException if the test is interrupted
+ */
+ @Test
+ public void testNoArgs() throws IOException, InterruptedException {
+ final String[] args = new String[] {};
+
+ final String outString = runEditor(args);
+ assertTrue(outString.startsWith("Apex Editor REST endpoint (ApexEditorMain: "
+ + "Config=[ApexEditorParameters: URI=http://0.0.0.0:18989/apexservices/, TTL=-1sec], "
+ + "State=READY) starting at http://0.0.0.0:18989/apexservices/"));
+ assertTrue(outString.contains("Apex Editor REST endpoint (ApexEditorMain: "
+ + "Config=[ApexEditorParameters: URI=http://0.0.0.0:18989/apexservices/, TTL=-1sec], "
+ + "State=RUNNING) started at http://0.0.0.0:18989/apexservices/"));
+ assertTrue(outString.replaceAll("[\\r?\\n]+", " ").endsWith("Apex Editor REST endpoint (ApexEditorMain: "
+ + "Config=[ApexEditorParameters: URI=http://0.0.0.0:18989/apexservices/, TTL=-1sec], State=STOPPED) shut down "));
+ }
+
+ /**
+ * Test bad arg 0.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ * @throws InterruptedException if the test is interrupted
+ */
+ @Test
+ public void testBadArg0() throws IOException, InterruptedException {
+ final String[] args = new String[] { "12321" };
+
+ try {
+ runEditor(args);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertTrue(e.getLocalizedMessage().startsWith("Apex Editor REST endpoint (ApexEditorMain: "
+ + "Config=[null], State=STOPPED) parameter error, too many command line arguments specified : [12321]"));
+ }
+ }
+
+ /**
+ * Test bad arg 1.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ * @throws InterruptedException if the test is interrupted
+ */
+ @Test
+ public void testBadArg1() throws IOException, InterruptedException {
+ final String[] args = new String[] { "12321 12322 12323" };
+
+ try {
+ runEditor(args);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertTrue(e.getLocalizedMessage().startsWith("Apex Editor REST endpoint (ApexEditorMain: "
+ + "Config=[null], State=STOPPED) parameter error, too many command line arguments specified : [12321 12322 12323]"));
+ }
+ }
+
+ /**
+ * Test bad arg 2.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ * @throws InterruptedException if the test is interrupted
+ */
+ @Test
+ public void testBadArg2() throws IOException, InterruptedException {
+ final String[] args = new String[] { "-z" };
+
+ try {
+ runEditor(args);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertTrue(e.getLocalizedMessage().startsWith("Apex Editor REST endpoint (ApexEditorMain: "
+ + "Config=[null], State=STOPPED) parameter error, invalid command line arguments specified : Unrecognized option: -z"));
+ }
+ }
+
+ /**
+ * Test bad arg 3.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ * @throws InterruptedException if the test is interrupted
+ */
+ @Test
+ public void testBadArg3() throws IOException, InterruptedException {
+ final String[] args = new String[] { "--hello" };
+
+ try {
+ runEditor(args);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertTrue(e.getLocalizedMessage().startsWith("Apex Editor REST endpoint (ApexEditorMain: "
+ + "Config=[null], State=STOPPED) parameter error, invalid command line arguments specified : Unrecognized option: --hello"));
+ }
+ }
+
+
+ /**
+ * Test bad arg 4.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ * @throws InterruptedException if the test is interrupted
+ */
+ @Test
+ public void testBadArg4() throws IOException, InterruptedException {
+ final String[] args = new String[] { "-l", "+++++" };
+
+ try {
+ runEditor(args);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertTrue(e.getLocalizedMessage()
+ .startsWith("Apex Editor REST endpoint (ApexEditorMain: "
+ + "Config=[ApexEditorParameters: URI=http://+++++:18989/apexservices/, TTL=-1sec], "
+ + "State=STOPPED) parameters invalid, listen address is not valid. "
+ + "Illegal character in hostname at index 7: http://+++++:18989/apexservices/"));
+ }
+ }
+
+ /**
+ * Test help 0.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ * @throws InterruptedException if the test is interrupted
+ */
+ @Test
+ public void testHelp0() throws IOException, InterruptedException {
+ final String[] args = new String[] { "--help" };
+
+ try {
+ runEditor(args);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertTrue(e.getMessage()
+ .startsWith("usage: org.onap.policy.apex.client.editor.rest.ApexEditorMain [options...]"));
+ }
+ }
+
+ /**
+ * Test help 1.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ * @throws InterruptedException if the test is interrupted
+ */
+ @Test
+ public void testHelp1() throws IOException, InterruptedException {
+ final String[] args = new String[] { "-h" };
+
+ try {
+ runEditor(args);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertTrue(e.getMessage()
+ .startsWith("usage: org.onap.policy.apex.client.editor.rest.ApexEditorMain [options...]"));
+ }
+ }
+
+ /**
+ * Test port arg.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ * @throws InterruptedException if the test is interrupted
+ */
+ @Test
+ public void testPortArgShJo() throws IOException, InterruptedException {
+ final String[] args = new String[] { "-p12321" };
+
+ final String outString = runEditor(args);
+
+ assertTrue(outString.startsWith("Apex Editor REST endpoint (ApexEditorMain: "
+ + "Config=[ApexEditorParameters: URI=http://0.0.0.0:12321/apexservices/, TTL=-1sec], "
+ + "State=READY) starting at http://0.0.0.0:12321/apexservices/"));
+ assertTrue(outString.contains("Apex Editor REST endpoint (ApexEditorMain: "
+ + "Config=[ApexEditorParameters: URI=http://0.0.0.0:12321/apexservices/, TTL=-1sec], "
+ + "State=RUNNING) started at http://0.0.0.0:12321/apexservices/"));
+ assertTrue(outString.replaceAll("[\\r?\\n]+", " ").endsWith("Apex Editor REST endpoint (ApexEditorMain: "
+ + "Config=[ApexEditorParameters: URI=http://0.0.0.0:12321/apexservices/, TTL=-1sec], State=STOPPED) shut down "));
+ }
+
+ /**
+ * Test port arg.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ * @throws InterruptedException if the test is interrupted
+ */
+ @Test
+ public void testPortArgShSe() throws IOException, InterruptedException {
+ final String[] args = new String[] { "-p", "12321" };
+
+ final String outString = runEditor(args);
+
+ assertTrue(outString.startsWith("Apex Editor REST endpoint (ApexEditorMain: "
+ + "Config=[ApexEditorParameters: URI=http://0.0.0.0:12321/apexservices/, TTL=-1sec], "
+ + "State=READY) starting at http://0.0.0.0:12321/apexservices/"));
+ assertTrue(outString.contains("Apex Editor REST endpoint (ApexEditorMain: "
+ + "Config=[ApexEditorParameters: URI=http://0.0.0.0:12321/apexservices/, TTL=-1sec], "
+ + "State=RUNNING) started at http://0.0.0.0:12321/apexservices/"));
+ assertTrue(outString.replaceAll("[\\r?\\n]+", " ").endsWith("(ApexEditorMain: "
+ + "Config=[ApexEditorParameters: URI=http://0.0.0.0:12321/apexservices/, TTL=-1sec], State=STOPPED) shut down "));
+ }
+
+
+ /**
+ * Test port arg.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ * @throws InterruptedException if the test is interrupted
+ */
+ @Test
+ public void testPortArgSpace() throws IOException, InterruptedException {
+ final String[] args = new String[] { "-p 12321" };
+
+ try {
+ runEditor(args);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertTrue(e.getMessage().startsWith("Apex Editor REST endpoint (ApexEditorMain: "
+ + "Config=[null], State=STOPPED) parameter error, error parsing argument \"port\" :For input string: \" 12321\""));
+ }
+ }
+
+ /**
+ * Test bad port arg 0.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ * @throws InterruptedException if the test is interrupted
+ */
+ @Test
+ public void testBadPortArgs0() throws IOException, InterruptedException {
+ final String[] args = new String[] { "-p0" };
+
+ try {
+ runEditor(args);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertTrue(e.getMessage()
+ .startsWith("Apex Editor REST endpoint (ApexEditorMain: "
+ + "Config=[ApexEditorParameters: URI=http://0.0.0.0:0/apexservices/, TTL=-1sec], "
+ + "State=STOPPED) parameters invalid, port must be between 1024 and 65535"));
+ }
+ }
+
+ /**
+ * Test bad port arg 1023.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ * @throws InterruptedException if the test is interrupted
+ */
+ @Test
+ public void testBadPortArgs1023() throws IOException, InterruptedException {
+ final String[] args = new String[] { "-p1023" };
+
+ try {
+ runEditor(args);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertTrue(e.getMessage()
+ .startsWith("Apex Editor REST endpoint (ApexEditorMain: "
+ + "Config=[ApexEditorParameters: URI=http://0.0.0.0:1023/apexservices/, TTL=-1sec], "
+ + "State=STOPPED) parameters invalid, port must be between 1024 and 65535"));
+ }
+ }
+
+ /**
+ * Test bad port arg 65536.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ * @throws InterruptedException if the test is interrupted
+ */
+ @Test
+ public void testBadPortArgs65536() throws IOException, InterruptedException {
+ final String[] args = new String[] { "-p65536" };
+
+ try {
+ runEditor(args);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertTrue(e.getMessage()
+ .startsWith("Apex Editor REST endpoint (ApexEditorMain: "
+ + "Config=[ApexEditorParameters: URI=http://0.0.0.0:65536/apexservices/, TTL=-1sec], "
+ + "State=STOPPED) parameters invalid, port must be between 1024 and 65535"));
+ }
+ }
+
+ /**
+ * Test TTL arg 0.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ * @throws InterruptedException if the test is interrupted
+ */
+ @Test
+ public void testTTLArg0() throws IOException, InterruptedException {
+ final String[] args = new String[] { "-t10" };
+
+ final String outString = runEditor(args);
+
+ assertTrue(outString.startsWith("Apex Editor REST endpoint (ApexEditorMain: "
+ + "Config=[ApexEditorParameters: URI=http://0.0.0.0:18989/apexservices/, TTL=10sec], "
+ + "State=READY) starting at http://0.0.0.0:18989/apexservices/"));
+ assertTrue(outString.replaceAll("[\\r?\\n]+", " ").contains("Apex Editor REST endpoint (ApexEditorMain: "
+ + "Config=[ApexEditorParameters: URI=http://0.0.0.0:18989/apexservices/, TTL=10sec], State=RUNNING) started"));
+ assertTrue(outString.replaceAll("[\\r?\\n]+", " ").endsWith("Apex Editor REST endpoint (ApexEditorMain: "
+ + "Config=[ApexEditorParameters: URI=http://0.0.0.0:18989/apexservices/, TTL=10sec], State=STOPPED) shut down "));
+ }
+
+ /**
+ * Test TTL arg 10.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ * @throws InterruptedException if the test is interrupted
+ */
+ @Test
+ public void testTTLArg1() throws IOException, InterruptedException {
+ final String[] args = new String[] { "-t", "10", "-l", "localhost" };
+
+ final String outString = runEditor(args);
+
+ assertTrue(outString.startsWith("Apex Editor REST endpoint (ApexEditorMain: "
+ + "Config=[ApexEditorParameters: URI=http://localhost:18989/apexservices/, TTL=10sec], "
+ + "State=READY) starting at http://localhost:18989/apexservices/"));
+ assertTrue(outString.replaceAll("[\\r?\\n]+", " ").contains("Apex Editor REST endpoint (ApexEditorMain: "
+ + "Config=[ApexEditorParameters: URI=http://localhost:18989/apexservices/, TTL=10sec], State=RUNNING) started"));
+ assertTrue(outString.replaceAll("[\\r?\\n]+", " ").endsWith("Apex Editor REST endpoint (ApexEditorMain: "
+ + "Config=[ApexEditorParameters: URI=http://localhost:18989/apexservices/, TTL=10sec], State=STOPPED) shut down "));
+ }
+
+ /**
+ * Test port TTL arg 0.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ * @throws InterruptedException if the test is interrupted
+ */
+ @Test
+ public void testPortTTLArg0() throws IOException, InterruptedException {
+ final String[] args = new String[] { "-t", "10", "-p", "12321" };
+
+ final String outString = runEditor(args);
+
+ assertTrue(outString.startsWith("Apex Editor REST endpoint (ApexEditorMain: "
+ + "Config=[ApexEditorParameters: URI=http://0.0.0.0:12321/apexservices/, TTL=10sec], "
+ + "State=READY) starting at http://0.0.0.0:12321/apexservices/"));
+ assertTrue(outString.replaceAll("[\\r?\\n]+", " ").contains("Apex Editor REST endpoint (ApexEditorMain: "
+ + "Config=[ApexEditorParameters: URI=http://0.0.0.0:12321/apexservices/, TTL=10sec], State=RUNNING) started"));
+ assertTrue(outString.replaceAll("[\\r?\\n]+", " ").endsWith("Apex Editor REST endpoint (ApexEditorMain: "
+ + "Config=[ApexEditorParameters: URI=http://0.0.0.0:12321/apexservices/, TTL=10sec], State=STOPPED) shut down "));
+ }
+
+
+ /**
+ * Test port TTL arg 10.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ * @throws InterruptedException if the test is interrupted
+ */
+ @Test
+ public void testPortTTLArg1() throws IOException, InterruptedException {
+ final String[] args = new String[] { "--time-to-live", "10", "--port", "12321", "--listen", "127.0.0.1" };
+
+ final String outString = runEditor(args);
+
+ assertTrue(outString.startsWith("Apex Editor REST endpoint (ApexEditorMain: "
+ + "Config=[ApexEditorParameters: URI=http://127.0.0.1:12321/apexservices/, TTL=10sec], "
+ + "State=READY) starting at http://127.0.0.1:12321/apexservices/"));
+ assertTrue(outString.replaceAll("[\\r?\\n]+", " ").contains("Apex Editor REST endpoint (ApexEditorMain: "
+ + "Config=[ApexEditorParameters: URI=http://127.0.0.1:12321/apexservices/, TTL=10sec], State=RUNNING) started"));
+ assertTrue(outString.replaceAll("[\\r?\\n]+", " ").endsWith("Apex Editor REST endpoint (ApexEditorMain: "
+ + "Config=[ApexEditorParameters: URI=http://127.0.0.1:12321/apexservices/, TTL=10sec], State=STOPPED) shut down "));
+ }
+
+ /**
+ * Run the editor for tests.
+ *
+ * @param args the args
+ * @return the output string
+ * @throws InterruptedException if the test is interrupted
+ */
+ private String runEditor(final String[] args) throws InterruptedException {
+ final ByteArrayOutputStream outBAStream = new ByteArrayOutputStream();
+ final PrintStream outStream = new PrintStream(outBAStream);
+
+ final ApexEditorMain editorMain = new ApexEditorMain(args, outStream);
+
+ // This test must be started in a thread because we want to intercept the output in cases where the editor is
+ // started infinitely
+ final Runnable testThread = new Runnable() {
+ @Override
+ public void run() {
+ editorMain.init();
+ }
+ };
+ new Thread(testThread).start();
+ while (editorMain.getState().equals(EditorState.READY)
+ || editorMain.getState().equals(EditorState.INITIALIZING)) {
+ Thread.sleep(100);
+ }
+
+ editorMain.shutdown();
+ final String outString = outBAStream.toString();
+ System.out.println(outString);
+ return outString;
+ }
+}
diff --git a/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/TestExceptions.java b/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/TestExceptions.java
new file mode 100644
index 000000000..c60fb8f4c
--- /dev/null
+++ b/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/TestExceptions.java
@@ -0,0 +1,41 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.client.editor.rest;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.io.IOException;
+
+import org.junit.Test;
+
+/**
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class TestExceptions {
+
+ @Test
+ public void test() {
+ assertNotNull(new ApexEditorException("Message"));
+ assertNotNull(new ApexEditorException("Message", "Object of Exception"));
+ assertNotNull(new ApexEditorException("Message", new IOException()));
+ assertNotNull(new ApexEditorException("Message", new IOException(), "Object of Exception"));
+ }
+}
diff --git a/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/bean/BeanFake.java b/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/bean/BeanFake.java
new file mode 100644
index 000000000..5648e306f
--- /dev/null
+++ b/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/bean/BeanFake.java
@@ -0,0 +1,47 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.client.editor.rest.bean;
+
+import javax.xml.bind.annotation.XmlType;
+
+/**
+ * The Event Bean.
+ */
+@XmlType
+public class BeanFake extends BeanBase {
+
+ private String name = null, version = null, field1 = null;
+ private int field2 = 0, field3 = 0;
+
+ public String getName() {
+ field1 = name;
+ return field1;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public int getField2() {
+ field3 = field2;
+ return field3;
+ }
+}
diff --git a/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/bean/TestBeans.java b/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/bean/TestBeans.java
new file mode 100644
index 000000000..50d330bf8
--- /dev/null
+++ b/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/bean/TestBeans.java
@@ -0,0 +1,87 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.client.editor.rest.bean;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+
+/**
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class TestBeans {
+
+ @Test
+ public void testBeans() {
+ assertNotNull(new BeanEvent().toString());
+ assertNotNull(new BeanState().toString());
+ assertNotNull(new BeanContextAlbum().toString());
+ assertNotNull(new BeanPolicy().toString());
+ assertNotNull(new BeanContextSchema().toString());
+ assertNotNull(new BeanField().toString());
+ assertNotNull(new BeanModel().toString());
+ assertNotNull(new BeanLogic().toString());
+ assertNotNull(new BeanStateOutput().toString());
+ assertNotNull(new BeanTaskParameter().toString());
+ assertNotNull(new BeanKeyRef().toString());
+ assertNotNull(new BeanStateTaskRef().toString());
+ assertNotNull(new BeanTask().toString());
+
+ final BeanState beanState = new BeanState();
+ assertNull(beanState.getName());
+ beanState.setDefaultTask(new BeanKeyRef());
+ assertNotNull(beanState.getDefaultTask());
+
+ final BeanEvent beanEvent = new BeanEvent();
+ assertNull(beanEvent.get("name"));
+
+ final BeanFake beanFake = new BeanFake();
+ assertNull(beanFake.get("name"));
+ assertNull(beanFake.get("field1"));
+
+ try {
+ beanFake.get("iDontExist");
+ fail("test should throw an exception here");
+ } catch (final IllegalArgumentException e) {
+ assertNotNull(e);
+ }
+ try {
+ beanFake.get("nome");
+ fail("test should throw an exception here");
+ } catch (final IllegalArgumentException e) {
+ assertNotNull(e);
+ }
+ try {
+ beanFake.get("field2");
+ fail("test should throw an exception here");
+ } catch (final IllegalArgumentException e) {
+ assertNotNull(e);
+ }
+ try {
+ beanFake.get("field3");
+ fail("test should throw an exception here");
+ } catch (final IllegalArgumentException e) {
+ assertNotNull(e);
+ }
+ }
+}