Example #1
0
  @Test
  public void testGenerateMultipleStateMultipleActionCommands() throws Exception {
    DomainModel domainModel = parseHelper.parse(MULTIPLE_STATES_MULTIPLE_ACTION_COMMANDS_RIM);
    ResourceInteractionModel model = (ResourceInteractionModel) domainModel.getRims().get(0);
    InMemoryFileSystemAccess fsa = new InMemoryFileSystemAccess();
    underTest.doGenerate(model.eResource(), fsa);

    String resouceAKey = IFileSystemAccess.DEFAULT_OUTPUT + "Test/AResourceState.java";
    assertTrue(fsa.getFiles().containsKey(resouceAKey));
    String resourceA = fsa.getFiles().get(resouceAKey).toString();
    int indexOfFirstNewProperties = resourceA.indexOf("actionViewProperties = new Properties()");
    assertTrue(indexOfFirstNewProperties > 0);
    assertTrue(resourceA.contains("actionViewProperties.put(\"key\", \"value\""));
    assertTrue(
        resourceA.contains("new Action(\"DoStuff\", Action.TYPE.ENTRY, actionViewProperties)"));

    String resouceBKey = IFileSystemAccess.DEFAULT_OUTPUT + "Test/BResourceState.java";
    assertTrue(fsa.getFiles().containsKey(resouceBKey));
    String resourceB = fsa.getFiles().get(resouceBKey).toString();
    int indexOfSecondNewProperties =
        resourceB.indexOf("actionViewProperties = new Properties()", indexOfFirstNewProperties);
    assertTrue(indexOfSecondNewProperties > 0);
    assertTrue(resourceB.contains("actionViewProperties.put(\"keyB\", \"valueB\""));
    assertTrue(
        resourceB.contains("new Action(\"DoSomeStuff\", Action.TYPE.ENTRY, actionViewProperties)"));
    assertTrue(resourceB.contains("actionViewProperties.put(\"keyB0\", \"valueB0\""));
    assertTrue(resourceB.contains("actionViewProperties.put(\"keyB1\", \"valueB1\""));
    assertTrue(
        resourceB.contains(
            "new Action(\"DoSomeMoreStuff\", Action.TYPE.ENTRY, actionViewProperties)"));
  }
Example #2
0
 @Test
 public void testGenerateFromIncompleteRIM() throws Exception {
   DomainModel model = parseHelper.parse(INCOMPLETE_RIM);
   InMemoryFileSystemAccess fsa = new InMemoryFileSystemAccess();
   boolean exceptionThrown = false;
   try {
     underTest.doGenerate(model.eResource(), fsa);
   } catch (RuntimeException e) {
     exceptionThrown = true;
   }
   assertFalse(exceptionThrown);
 }
Example #3
0
  @Test
  public void testGenerateUpdateTransition() throws Exception {
    DomainModel domainModel = parseHelper.parse(TRANSITION_WITH_UPDATE_EVENT);
    ResourceInteractionModel model = (ResourceInteractionModel) domainModel.getRims().get(0);
    InMemoryFileSystemAccess fsa = new InMemoryFileSystemAccess();
    underTest.doGenerate(model.eResource(), fsa);

    String resourceAKey = IFileSystemAccess.DEFAULT_OUTPUT + "Test/AResourceState.java";
    assertTrue(fsa.getFiles().containsKey(resourceAKey));
    String resourceA = fsa.getFiles().get(resourceAKey).toString();
    assertTrue(resourceA.contains("sA.addTransition(new Transition.Builder()"));
    assertTrue(resourceA.contains(".flags(Transition.FOR_EACH)"));
    assertTrue(resourceA.contains(".method(\"GET\")"));
    assertTrue(resourceA.contains(".target(sB)"));
    assertTrue(resourceA.contains(".uriParameters(uriLinkageProperties)"));
    assertTrue(
        resourceA.contains(
            ".evaluation(conditionalLinkExpressions != null ? new SimpleLogicalExpressionEvaluator(conditionalLinkExpressions) : null)"));
    assertTrue(resourceA.contains(".label(\"B\")"));

    String resourceBKey = IFileSystemAccess.DEFAULT_OUTPUT + "Test/BResourceState.java";
    assertTrue(fsa.getFiles().containsKey(resourceBKey));
    String resourceB = fsa.getFiles().get(resourceBKey).toString();
    assertTrue(resourceB.contains("sB.addTransition(new Transition.Builder()"));
    assertTrue(resourceB.contains(".method(\"PUT\")"));
    assertTrue(resourceB.contains(".target(sB_pseudo)"));
    assertTrue(resourceB.contains(".uriParameters(uriLinkageProperties)"));
    assertTrue(
        resourceB.contains(
            ".evaluation(conditionalLinkExpressions != null ? new SimpleLogicalExpressionEvaluator(conditionalLinkExpressions) : null)"));
    assertTrue(resourceB.contains(".label(\"B_pseudo\")"));

    String resourceB_pseudoKey =
        IFileSystemAccess.DEFAULT_OUTPUT + "Test/B_pseudoResourceState.java";
    assertTrue(fsa.getFiles().containsKey(resourceB_pseudoKey));
    String resourceB_pseudo = fsa.getFiles().get(resourceB_pseudoKey).toString();
    assertTrue(resourceB_pseudo.contains("sB_pseudo.addTransition(new Transition.Builder()"));
    assertTrue(resourceB_pseudo.contains(".flags(Transition.AUTO)"));
    assertTrue(resourceB_pseudo.contains(".target(sA)"));
    assertTrue(resourceB_pseudo.contains(".uriParameters(uriLinkageProperties)"));
    assertTrue(
        resourceB_pseudo.contains(
            ".evaluation(conditionalLinkExpressions != null ? new SimpleLogicalExpressionEvaluator(conditionalLinkExpressions) : null)"));

    assertTrue(resourceB_pseudo.contains("sB_pseudo.addTransition(new Transition.Builder()"));
    assertTrue(resourceB_pseudo.contains(".flags(Transition.AUTO)"));
    assertTrue(resourceB_pseudo.contains(".target(sB)"));
    assertTrue(resourceB_pseudo.contains(".uriParameters(uriLinkageProperties)"));
    assertTrue(
        resourceB_pseudo.contains(
            ".evaluation(conditionalLinkExpressions != null ? new SimpleLogicalExpressionEvaluator(conditionalLinkExpressions) : null)"));
  }
Example #4
0
  /*
   * doGenerate should producer one file per resource
   */
  @Test
  public void testGenerateOneFile() throws Exception {
    DomainModel domainModel = parseHelper.parse(SINGLE_STATE_VIEW_COMMAND_ONLY_RIM);
    ResourceInteractionModel model = (ResourceInteractionModel) domainModel.getRims().get(0);
    InMemoryFileSystemAccess fsa = new InMemoryFileSystemAccess();
    underTest.doGenerate(model.eResource(), fsa);
    System.out.println(fsa.getFiles());
    assertEquals(2, fsa.getFiles().size());

    assertTrue(fsa.getFiles().containsKey(IFileSystemAccess.DEFAULT_OUTPUT + "TestBehaviour.java"));
    assertTrue(
        fsa.getFiles().containsKey(IFileSystemAccess.DEFAULT_OUTPUT + "Test/AResourceState.java"));
  }
Example #5
0
  @Test
  public void testGenerateSingleStateViewCommandOnly() throws Exception {
    DomainModel domainModel = parseHelper.parse(SINGLE_STATE_VIEW_COMMAND_ONLY_RIM);
    InMemoryFileSystemAccess fsa = new InMemoryFileSystemAccess();
    underTest.doGenerate(domainModel.eResource(), fsa);

    String expectedKey = IFileSystemAccess.DEFAULT_OUTPUT + "Test/AResourceState.java";
    assertTrue(fsa.getFiles().containsKey(expectedKey));
    assertTrue(
        fsa.getFiles()
            .get(expectedKey)
            .toString()
            .contains("new Action(\"GetEntity\", Action.TYPE.VIEW, new Properties())"));
  }
Example #6
0
  @Test
  public void testGenerateOnErrorResourceSeparateRIM() throws Exception {
    DomainModel domainModel = parseHelper.parse(RESOURCE_ON_ERROR_SEPARATE_RIM);
    InMemoryFileSystemAccess fsa = new InMemoryFileSystemAccess();
    underTest.doGenerate(domainModel.eResource(), fsa);

    // collection
    String expectedKey = IFileSystemAccess.DEFAULT_OUTPUT + "ErrorTest/Test/AResourceState.java";
    assertTrue(fsa.getFiles().containsKey(expectedKey));
    String output = fsa.getFiles().get(expectedKey).toString();
    assertTrue(
        output.contains(
            "super(\"ENTITY\", \"A\", createActions(), \"/A\", createLinkRelations(), null, factory.getResourceState(\"ErrorTest.Error.AE\"));"));
  }
Example #7
0
  @Test
  public void testGenerateResourceWithBasepath() throws Exception {
    DomainModel domainModel = parseHelper.parse(RESOURCE_WITH_BASEPATH);
    ResourceInteractionModel model = (ResourceInteractionModel) domainModel.getRims().get(0);
    InMemoryFileSystemAccess fsa = new InMemoryFileSystemAccess();
    underTest.doGenerate(model.eResource(), fsa);

    // collection
    String expectedKey = IFileSystemAccess.DEFAULT_OUTPUT + "Test/AResourceState.java";
    assertTrue(fsa.getFiles().containsKey(expectedKey));
    String output = fsa.getFiles().get(expectedKey).toString();
    assertTrue(
        output.contains(
            "super(\"ENTITY\", \"A\", createActions(), \"/{companyid}/A\", createLinkRelations(), null, null);"));
  }
Example #8
0
  @Test
  public void testGenerateAutoTransitionsWithUriLinkage() throws Exception {
    DomainModel domainModel = parseHelper.parse(AUTO_TRANSITION_WITH_URI_LINKAGE_RIM);
    ResourceInteractionModel model = (ResourceInteractionModel) domainModel.getRims().get(0);
    InMemoryFileSystemAccess fsa = new InMemoryFileSystemAccess();
    underTest.doGenerate(model.eResource(), fsa);

    String expectedKey =
        IFileSystemAccess.DEFAULT_OUTPUT + "Test/create_pseudo_stateResourceState.java";
    assertTrue(fsa.getFiles().containsKey(expectedKey));
    String output = fsa.getFiles().get(expectedKey).toString();

    assertTrue(output.contains("uriLinkageProperties.put(\"id\", \"{MyId}\");"));
    assertTrue(output.contains("screate_pseudo_state.addTransition(new Transition.Builder()"));
    assertTrue(output.contains(".target(screated)"));
  }
Example #9
0
  @Test
  public void testGenerateResourcesWithGlobalRelations() throws Exception {
    DomainModel domainModel = parseHelper.parse(GLOBAL_RESOURCE_RELATIONS_RIM);
    ResourceInteractionModel model = (ResourceInteractionModel) domainModel.getRims().get(0);
    InMemoryFileSystemAccess fsa = new InMemoryFileSystemAccess();
    underTest.doGenerate(model.eResource(), fsa);

    // collection
    String expectedKey =
        IFileSystemAccess.DEFAULT_OUTPUT + "Test/accTransactionsResourceState.java";
    assertTrue(fsa.getFiles().containsKey(expectedKey));
    String accTransactionsOutput = fsa.getFiles().get(expectedKey).toString();
    // the constructor part
    assertTrue(accTransactionsOutput.contains("\"/accTransactions\", createLinkRelations()"));
    // createLinkRelations method
    String expectedAccTransactionsRelArray =
        ""
            + "        String accTransactionsRelationsStr = \"\";"
            + LINE_SEP
            + "        accTransactionsRelationsStr += \"archive \";"
            + LINE_SEP
            + "        accTransactionsRelationsStr += \"http://www.temenos.com/statement-entries \";"
            + LINE_SEP
            + "        String[] accTransactionsRelations = accTransactionsRelationsStr.trim().split(\" \");"
            + LINE_SEP
            + "";
    assertTrue(accTransactionsOutput.contains(expectedAccTransactionsRelArray));

    // item
    expectedKey = IFileSystemAccess.DEFAULT_OUTPUT + "Test/accTransactionResourceState.java";
    assertTrue(fsa.getFiles().containsKey(expectedKey));
    String accTransactionOutput = fsa.getFiles().get(expectedKey).toString();
    // the constructor part
    assertTrue(accTransactionOutput.contains("\"/accTransaction\", createLinkRelations()"));
    // createLinkRelations method
    String expectedAccTransactionRelArray =
        ""
            + "        String accTransactionRelationsStr = \"\";"
            + LINE_SEP
            + "        accTransactionRelationsStr += \"edit \";"
            + LINE_SEP
            + "        String[] accTransactionRelations = accTransactionRelationsStr.trim().split(\" \");"
            + LINE_SEP
            + "";
    assertTrue(accTransactionOutput.contains(expectedAccTransactionRelArray));
  }
Example #10
0
  @Test
  public void testGenerateEmbeddedTransitions() throws Exception {
    DomainModel domainModel = parseHelper.parse(EMBEDDED_TRANSITION_RIM);
    ResourceInteractionModel model = (ResourceInteractionModel) domainModel.getRims().get(0);
    InMemoryFileSystemAccess fsa = new InMemoryFileSystemAccess();
    underTest.doGenerate(model.eResource(), fsa);

    String expectedKey = IFileSystemAccess.DEFAULT_OUTPUT + "Test/AResourceState.java";
    assertTrue(fsa.getFiles().containsKey(expectedKey));
    String output = fsa.getFiles().get(expectedKey).toString();

    assertTrue(output.contains("sA.addTransition(new Transition.Builder()"));
    assertTrue(output.contains(".target(sB)"));
    assertTrue(output.contains(".flags(Transition.EMBEDDED)"));

    String expectedBKey = IFileSystemAccess.DEFAULT_OUTPUT + "Test/BResourceState.java";
    assertTrue(fsa.getFiles().containsKey(expectedBKey));
  }
Example #11
0
  @Test
  public void testGenerateTransitionsWithExpressions() throws Exception {
    DomainModel domainModel = parseHelper.parse(TRANSITION_WITH_EXPRESSION_RIM);
    ResourceInteractionModel model = (ResourceInteractionModel) domainModel.getRims().get(0);
    InMemoryFileSystemAccess fsa = new InMemoryFileSystemAccess();
    underTest.doGenerate(model.eResource(), fsa);

    String expectedKey = IFileSystemAccess.DEFAULT_OUTPUT + "Test/AResourceState.java";
    assertTrue(fsa.getFiles().containsKey(expectedKey));
    String output = fsa.getFiles().get(expectedKey).toString();

    final String NEW_STATEMENT = "conditionalLinkExpressions = new ArrayList<Expression>();";
    final String ADD_TRANSITION =
        ".method(\"GET\").target(sB).uriParameters(uriLinkageProperties).evaluation(conditionalLinkExpressions != null ? new SimpleLogicalExpressionEvaluator(conditionalLinkExpressions) : null).label(\"B\")";

    int indexOfNewStatement = output.indexOf(NEW_STATEMENT);
    assertTrue(indexOfNewStatement > 0);
    assertTrue(
        output.contains(
            "conditionalLinkExpressions.add(new ResourceGETExpression(factory.getResourceState(\"Test.B\"), ResourceGETExpression.Function.OK))"));
    int indexOfAddTransition = output.indexOf(ADD_TRANSITION);
    assertTrue(indexOfAddTransition > 0);

    indexOfNewStatement = output.indexOf(NEW_STATEMENT, indexOfNewStatement);
    assertTrue(indexOfNewStatement > 0);
    assertTrue(
        output.contains(
            "conditionalLinkExpressions.add(new ResourceGETExpression(factory.getResourceState(\"Test.B\"), ResourceGETExpression.Function.NOT_FOUND))"));
    indexOfAddTransition = output.indexOf(ADD_TRANSITION, indexOfAddTransition);
    assertTrue(indexOfAddTransition > 0);

    indexOfNewStatement = output.indexOf(NEW_STATEMENT, indexOfNewStatement);
    assertTrue(indexOfNewStatement > 0);
    assertTrue(
        output.contains(
            "conditionalLinkExpressions.add(new ResourceGETExpression(factory.getResourceState(\"Test.C\"), ResourceGETExpression.Function.OK))"));
    assertTrue(
        output.contains(
            "conditionalLinkExpressions.add(new ResourceGETExpression(factory.getResourceState(\"Test.D\"), ResourceGETExpression.Function.NOT_FOUND))"));
    indexOfAddTransition = output.indexOf(ADD_TRANSITION, indexOfAddTransition);
    assertTrue(indexOfAddTransition > 0);
  }
Example #12
0
  /*
   * doGenerate should producer one file per resource
   */
  @Test
  public void testGenerateFileInPackage() throws Exception {
    DomainModel domainModel = parseHelper.parse(SINGLE_STATE_WITH_PACKAGE_RIM);
    InMemoryFileSystemAccess fsa = new InMemoryFileSystemAccess();
    underTest.doGenerate(domainModel.eResource(), fsa);
    System.out.println(fsa.getFiles());
    assertEquals(2, fsa.getFiles().size());

    String expectedKey = IFileSystemAccess.DEFAULT_OUTPUT + "blah/TestBehaviour.java";
    assertTrue(fsa.getFiles().containsKey(expectedKey));
    String output = fsa.getFiles().get(expectedKey).toString();
    assertTrue(output.contains("package blah;"));
    assertTrue(output.contains("public class TestBehaviour {"));
    assertTrue(output.contains("getRIM"));
    assertTrue(output.contains("factory.getResourceState(\"blah.Test.A\");"));

    String expectedRSKey = IFileSystemAccess.DEFAULT_OUTPUT + "blah/Test/AResourceState.java";
    assertTrue(fsa.getFiles().containsKey(expectedRSKey));
    String outputRS = fsa.getFiles().get(expectedRSKey).toString();
    assertTrue(outputRS.contains("package blah.Test;"));
  }
Example #13
0
  @Test
  public void testGenerateSingleStateActionCommands() throws Exception {
    DomainModel domainModel = parseHelper.parse(SINGLE_STATE_ACTION_COMMANDS_RIM);
    ResourceInteractionModel model = (ResourceInteractionModel) domainModel.getRims().get(0);
    InMemoryFileSystemAccess fsa = new InMemoryFileSystemAccess();
    underTest.doGenerate(model.eResource(), fsa);

    String expectedKey = IFileSystemAccess.DEFAULT_OUTPUT + "Test/AResourceState.java";
    assertTrue(fsa.getFiles().containsKey(expectedKey));

    String output = fsa.getFiles().get(expectedKey).toString();
    int indexOfFirstNewProperties = output.indexOf("actionViewProperties = new Properties()");
    assertTrue(indexOfFirstNewProperties > 0);
    assertTrue(output.contains("actionViewProperties.put(\"getkey\", \"getvalue\""));
    assertTrue(
        output.contains("new Action(\"GetEntity\", Action.TYPE.VIEW, actionViewProperties)"));

    // No onerror handler so should not define an error state
    assertTrue(
        output.contains(
            "super(\"ENTITY\", \"A\", createActions(), \"/A\", createLinkRelations(), null, null);"));
  }
Example #14
0
  @Test
  public void testGenerateSimpleStates() throws Exception {
    DomainModel domainModel = parseHelper.parse(SIMPLE_STATES_RIM);
    ResourceInteractionModel model = (ResourceInteractionModel) domainModel.getRims().get(0);
    InMemoryFileSystemAccess fsa = new InMemoryFileSystemAccess();
    underTest.doGenerate(model.eResource(), fsa);
    System.out.println(fsa.getFiles());
    assertEquals(4, fsa.getFiles().size());

    // the behaviour class
    String expectedKey = IFileSystemAccess.DEFAULT_OUTPUT + "SimpleBehaviour.java";
    assertTrue(fsa.getFiles().containsKey(expectedKey));
    assertEquals(SIMPLE_STATES_BEHAVIOUR, fsa.getFiles().get(expectedKey).toString());

    // one class per resource
    assertTrue(
        fsa.getFiles()
            .containsKey(IFileSystemAccess.DEFAULT_OUTPUT + "Simple/AResourceState.java"));
    assertTrue(
        fsa.getFiles()
            .containsKey(IFileSystemAccess.DEFAULT_OUTPUT + "Simple/BResourceState.java"));
  }