From 62475a30ef2d425fe04df35ef2dac53c7ab5306a Mon Sep 17 00:00:00 2001 From: Parshad Patel Date: Fri, 16 Nov 2018 20:59:14 +0900 Subject: Rename test classes in apex-pdp Make test classes name consistence by putting 'Test' at end Issue-ID: POLICY-1263 Change-Id: I0179388d84826e698276a1995dd8173a40b5fd2b Signed-off-by: Parshad Patel --- .../client/editor/rest/ApexEditorStartupTest.java | 457 ++++++ .../apex/client/editor/rest/ExceptionsTest.java | 42 + .../client/editor/rest/TestApexEditorStartup.java | 457 ------ .../apex/client/editor/rest/TestExceptions.java | 42 - .../rest/handling/ApexEditorRestResourceTest.java | 1506 ++++++++++++++++++++ .../rest/handling/TestApexEditorRestResource.java | 1506 -------------------- .../editor/rest/handling/bean/BeansTest.java | 88 ++ .../editor/rest/handling/bean/TestBeans.java | 88 -- 8 files changed, 2093 insertions(+), 2093 deletions(-) create mode 100644 client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/ApexEditorStartupTest.java create mode 100644 client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/ExceptionsTest.java delete mode 100644 client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/TestApexEditorStartup.java delete mode 100644 client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/TestExceptions.java create mode 100644 client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/handling/ApexEditorRestResourceTest.java delete mode 100644 client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/handling/TestApexEditorRestResource.java create mode 100644 client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/handling/bean/BeansTest.java delete mode 100644 client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/handling/bean/TestBeans.java (limited to 'client') diff --git a/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/ApexEditorStartupTest.java b/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/ApexEditorStartupTest.java new file mode 100644 index 000000000..54e40ae77 --- /dev/null +++ b/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/ApexEditorStartupTest.java @@ -0,0 +1,457 @@ +/*- + * ============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; + +/** + * Test Apex Editor Startup. + */ +public class ApexEditorStartupTest { + // 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://localhost:18989/apexservices/, TTL=-1sec], " + + "State=READY) starting at http://localhost:18989/apexservices/")); + assertTrue(outString.contains("Apex Editor REST endpoint (ApexEditorMain: " + + "Config=[ApexEditorParameters: URI=http://localhost:18989/apexservices/, TTL=-1sec], " + + "State=RUNNING) started at http://localhost:18989/apexservices/")); + assertTrue(outString.replaceAll("[\\r?\\n]+", " ").endsWith("Apex Editor REST endpoint (ApexEditorMain: " + + "Config=[ApexEditorParameters: URI=http://localhost: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://localhost:12321/apexservices/, TTL=-1sec], " + + "State=READY) starting at http://localhost:12321/apexservices/")); + assertTrue(outString.contains("Apex Editor REST endpoint (ApexEditorMain: " + + "Config=[ApexEditorParameters: URI=http://localhost:12321/apexservices/, TTL=-1sec], " + + "State=RUNNING) started at http://localhost:12321/apexservices/")); + assertTrue(outString.replaceAll("[\\r?\\n]+", " ").endsWith("Apex Editor REST endpoint (ApexEditorMain: " + + "Config=[ApexEditorParameters: URI=http://localhost: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://localhost:12321/apexservices/, TTL=-1sec], " + + "State=READY) starting at http://localhost:12321/apexservices/")); + assertTrue(outString.contains("Apex Editor REST endpoint (ApexEditorMain: " + + "Config=[ApexEditorParameters: URI=http://localhost:12321/apexservices/, TTL=-1sec], " + + "State=RUNNING) started at http://localhost:12321/apexservices/")); + assertTrue(outString.replaceAll("[\\r?\\n]+", " ").endsWith("(ApexEditorMain: " + + "Config=[ApexEditorParameters: URI=http://localhost: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://localhost: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://localhost: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://localhost: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://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 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://localhost:12321/apexservices/, TTL=10sec], " + + "State=READY) starting at http://localhost:12321/apexservices/")); + assertTrue(outString.replaceAll("[\\r?\\n]+", " ").contains("Apex Editor REST endpoint (ApexEditorMain: " + + "Config=[ApexEditorParameters: URI=http://localhost:12321/apexservices/, TTL=10sec], State=RUNNING)" + + " started")); + assertTrue(outString.replaceAll("[\\r?\\n]+", " ").endsWith("Apex Editor REST endpoint (ApexEditorMain: " + + "Config=[ApexEditorParameters: URI=http://localhost: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/ExceptionsTest.java b/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/ExceptionsTest.java new file mode 100644 index 000000000..987076fd1 --- /dev/null +++ b/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/ExceptionsTest.java @@ -0,0 +1,42 @@ +/*- + * ============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; + +/** + * Test Apex Editor Exceptions. + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class ExceptionsTest { + + @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/TestApexEditorStartup.java b/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/TestApexEditorStartup.java deleted file mode 100644 index 0fad411a5..000000000 --- a/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/TestApexEditorStartup.java +++ /dev/null @@ -1,457 +0,0 @@ -/*- - * ============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; - -/** - * Test Apex Editor Startup. - */ -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://localhost:18989/apexservices/, TTL=-1sec], " - + "State=READY) starting at http://localhost:18989/apexservices/")); - assertTrue(outString.contains("Apex Editor REST endpoint (ApexEditorMain: " - + "Config=[ApexEditorParameters: URI=http://localhost:18989/apexservices/, TTL=-1sec], " - + "State=RUNNING) started at http://localhost:18989/apexservices/")); - assertTrue(outString.replaceAll("[\\r?\\n]+", " ").endsWith("Apex Editor REST endpoint (ApexEditorMain: " - + "Config=[ApexEditorParameters: URI=http://localhost: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://localhost:12321/apexservices/, TTL=-1sec], " - + "State=READY) starting at http://localhost:12321/apexservices/")); - assertTrue(outString.contains("Apex Editor REST endpoint (ApexEditorMain: " - + "Config=[ApexEditorParameters: URI=http://localhost:12321/apexservices/, TTL=-1sec], " - + "State=RUNNING) started at http://localhost:12321/apexservices/")); - assertTrue(outString.replaceAll("[\\r?\\n]+", " ").endsWith("Apex Editor REST endpoint (ApexEditorMain: " - + "Config=[ApexEditorParameters: URI=http://localhost: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://localhost:12321/apexservices/, TTL=-1sec], " - + "State=READY) starting at http://localhost:12321/apexservices/")); - assertTrue(outString.contains("Apex Editor REST endpoint (ApexEditorMain: " - + "Config=[ApexEditorParameters: URI=http://localhost:12321/apexservices/, TTL=-1sec], " - + "State=RUNNING) started at http://localhost:12321/apexservices/")); - assertTrue(outString.replaceAll("[\\r?\\n]+", " ").endsWith("(ApexEditorMain: " - + "Config=[ApexEditorParameters: URI=http://localhost: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://localhost: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://localhost: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://localhost: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://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 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://localhost:12321/apexservices/, TTL=10sec], " - + "State=READY) starting at http://localhost:12321/apexservices/")); - assertTrue(outString.replaceAll("[\\r?\\n]+", " ").contains("Apex Editor REST endpoint (ApexEditorMain: " - + "Config=[ApexEditorParameters: URI=http://localhost:12321/apexservices/, TTL=10sec], State=RUNNING)" - + " started")); - assertTrue(outString.replaceAll("[\\r?\\n]+", " ").endsWith("Apex Editor REST endpoint (ApexEditorMain: " - + "Config=[ApexEditorParameters: URI=http://localhost: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 deleted file mode 100644 index e63fb9e45..000000000 --- a/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/TestExceptions.java +++ /dev/null @@ -1,42 +0,0 @@ -/*- - * ============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; - -/** - * Test Apex Editor Exceptions. - * @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/handling/ApexEditorRestResourceTest.java b/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/handling/ApexEditorRestResourceTest.java new file mode 100644 index 000000000..f0a847814 --- /dev/null +++ b/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/handling/ApexEditorRestResourceTest.java @@ -0,0 +1,1506 @@ +/*- + * ============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.handling; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +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; + +/** + * Test Apex Editor Rest Resource. + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class ApexEditorRestResourceTest 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 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()); + + String resultString = target("editor/" + corruptSessionId + "/Model/Download").request().get(String.class); + assertEquals("", resultString); + + resultString = target("editor/" + sessionId + "/Model/Download").request().get(String.class); + assertNotNull(resultString); + + resultString = target("editor/-12345/Model/Download").request().get(String.class); + assertEquals("", resultString); + + resultString = target("editor/12345/Model/Download").request().get(String.class); + assertEquals("", resultString); + + 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 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 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.CONCEPT_DOES_NOT_EXIST, result.getResult()); + + result = target("editor/" + sessionId + "/Validate/ContextAlbum").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/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 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 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.CONCEPT_DOES_NOT_EXIST, 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.CONCEPT_DOES_NOT_EXIST, 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 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 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.CONCEPT_DOES_NOT_EXIST, 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.CONCEPT_DOES_NOT_EXIST, 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 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 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.CONCEPT_DOES_NOT_EXIST, 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 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 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/handling/TestApexEditorRestResource.java b/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/handling/TestApexEditorRestResource.java deleted file mode 100644 index 3585959f5..000000000 --- a/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/handling/TestApexEditorRestResource.java +++ /dev/null @@ -1,1506 +0,0 @@ -/*- - * ============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.handling; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -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; - -/** - * Test Apex Editor Rest Resource. - * @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 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()); - - String resultString = target("editor/" + corruptSessionId + "/Model/Download").request().get(String.class); - assertEquals("", resultString); - - resultString = target("editor/" + sessionId + "/Model/Download").request().get(String.class); - assertNotNull(resultString); - - resultString = target("editor/-12345/Model/Download").request().get(String.class); - assertEquals("", resultString); - - resultString = target("editor/12345/Model/Download").request().get(String.class); - assertEquals("", resultString); - - 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 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 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.CONCEPT_DOES_NOT_EXIST, result.getResult()); - - result = target("editor/" + sessionId + "/Validate/ContextAlbum").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/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 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 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.CONCEPT_DOES_NOT_EXIST, 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.CONCEPT_DOES_NOT_EXIST, 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 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 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.CONCEPT_DOES_NOT_EXIST, 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.CONCEPT_DOES_NOT_EXIST, 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 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 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.CONCEPT_DOES_NOT_EXIST, 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 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 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/handling/bean/BeansTest.java b/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/handling/bean/BeansTest.java new file mode 100644 index 000000000..2cae7703d --- /dev/null +++ b/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/handling/bean/BeansTest.java @@ -0,0 +1,88 @@ +/*- + * ============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.handling.bean; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; + +import org.junit.Test; + +/** + * Test the beans. + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class BeansTest { + + @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); + } + } +} diff --git a/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/handling/bean/TestBeans.java b/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/handling/bean/TestBeans.java deleted file mode 100644 index 72cbae22c..000000000 --- a/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/handling/bean/TestBeans.java +++ /dev/null @@ -1,88 +0,0 @@ -/*- - * ============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.handling.bean; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.fail; - -import org.junit.Test; - -/** - * Test the beans. - * @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); - } - } -} -- cgit 1.2.3-korg