Esempio n. 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)"));
  }
  public QualifiedName getFullyQualifiedName(EObject obj) {
    QualifiedName partialQualifiedName = null;
    if (obj instanceof DomainDeclaration) {
      DomainDeclaration d = (DomainDeclaration) obj;
      partialQualifiedName = toQualifiedName(d.getName());
    } else if (obj instanceof ResourceInteractionModel) {
      ResourceInteractionModel r = (ResourceInteractionModel) obj;
      partialQualifiedName = toQualifiedName(r.getName());
    } else if (obj instanceof State) {
      State s = (State) obj;
      partialQualifiedName = toQualifiedName(s.getName());
    } else if (obj instanceof Event) {
      Event e = (Event) obj;
      partialQualifiedName = toQualifiedName(e.getName());
    } else if (obj instanceof Command) {
      Command c = (Command) obj;
      partialQualifiedName = toQualifiedName(c.getName());
    } else if (obj instanceof Relation) {
      Relation r = (Relation) obj;
      partialQualifiedName = toQualifiedName(r.getName());
    } else {
      return null;
    }

    if (partialQualifiedName != null) {
      EObject parent = obj.eContainer();
      QualifiedName parentsQualifiedName = getFullyQualifiedName(parent);
      if (parentsQualifiedName != null)
        partialQualifiedName = parentsQualifiedName.append(partialQualifiedName);
    }

    return partialQualifiedName;
  }
Esempio n. 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)"));
  }
Esempio n. 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"));
  }
Esempio n. 5
0
  @Test
  public void testGenerateOnErrorResource() throws Exception {
    DomainModel domainModel = parseHelper.parse(RESOURCE_ON_ERROR);
    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(), \"/A\", createLinkRelations(), null, factory.getResourceState(\"Test.AE\"));"));
  }
Esempio n. 6
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)"));
  }
Esempio n. 7
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));
  }
Esempio n. 8
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));
  }
Esempio n. 9
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);
  }
Esempio n. 10
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);"));
  }
Esempio n. 11
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"));
  }