Exemplo n.º 1
0
  @Test
  public void testRIMWithoutReciprocalLinks() {
    // Parse the test metadata
    MetadataParser parser = new MetadataParser();
    InputStream is =
        parser.getClass().getClassLoader().getResourceAsStream(METADATA_AIRLINE_XML_FILE);
    Metadata metadata = parser.parse(is);
    Assert.assertNotNull(metadata);

    // Define the interaction model
    InteractionModel interactionModel = new InteractionModel(metadata);

    // Do not specify a reciprocal link
    IMResourceStateMachine rsmFlightSchedule =
        interactionModel.findResourceStateMachine("FlightSchedule");
    IMResourceStateMachine rsmAirport = interactionModel.findResourceStateMachine("Airport");
    IMResourceStateMachine rsmFlight = interactionModel.findResourceStateMachine("Flight");
    IMResourceStateMachine rsmPassenger = interactionModel.findResourceStateMachine("Passenger");
    rsmFlight.addTransitionToEntityState(
        "flight", rsmFlightSchedule, "flightschedule", "flightScheduleNum", null);
    rsmFlightSchedule.addTransitionToEntityState(
        "flightschedule", rsmAirport, "departureAirport", "departureAirportCode", null);
    rsmFlightSchedule.addTransitionToEntityState(
        "flightschedule", rsmAirport, "arrivalAirport", "arrivalAirportCode", null);
    rsmAirport.addTransitionToCollectionState(
        "airport",
        rsmFlightSchedule,
        "departures",
        "departureAirportCode eq '{code}'",
        "departureAirportCode",
        "departures");
    rsmAirport.addTransitionToCollectionState(
        "airport",
        rsmFlightSchedule,
        "arrivals",
        "arrivalAirportCode eq '{code}'",
        "arrivalAirportCode",
        "arrivals");
    rsmPassenger.addTransitionToEntityState("passenger", rsmFlight, "flight", "flightID", "flight");

    // Run the generator
    MockGenerator generator = new MockGenerator();
    boolean status =
        generator.generateArtifacts(
            metadata,
            interactionModel,
            new File("target/FlightResponder/classes"),
            new File("target/FlightResponder/classes"),
            true);

    // Check results
    assertTrue(status);

    // Test rim dsl
    assertTrue(
        generator.generatedRimDsl.contains(
            "GET *-> flightschedule_departureAirport {"
                + RIM_LINE_SEP
                + "\t\tparameters [ id=\"{flightScheduleID}\" ]"
                + RIM_LINE_SEP
                + "\t}"));
    assertTrue(
        generator.generatedRimDsl.contains(
            "GET -> flightschedule_departureAirport {"
                + RIM_LINE_SEP
                + "\t\tparameters [ id=\"{flightScheduleID}\" ]"
                + RIM_LINE_SEP
                + "\t}"));
    assertTrue(
        generator.generatedRimDsl.contains(
            "GET *-> flightschedule_arrivalAirport {"
                + RIM_LINE_SEP
                + "\t\tparameters [ id=\"{flightScheduleID}\" ]"
                + RIM_LINE_SEP
                + "\t}"));
    assertTrue(
        generator.generatedRimDsl.contains(
            "GET -> flightschedule_arrivalAirport {"
                + RIM_LINE_SEP
                + "\t\tparameters [ id=\"{flightScheduleID}\" ]"
                + RIM_LINE_SEP
                + "\t}"));
    assertTrue(
        generator.generatedRimDsl.contains(
            "GET -> airport_arrivals {"
                + RIM_LINE_SEP
                + "\t\ttitle: \"arrivals\""
                + RIM_LINE_SEP
                + "\t\tparameters [ id=\"{code}\" ]"
                + RIM_LINE_SEP
                + "\t}"));
    assertTrue(
        generator.generatedRimDsl.contains(
            "GET -> airport_departures {"
                + RIM_LINE_SEP
                + "\t\ttitle: \"departures\""
                + RIM_LINE_SEP
                + "\t\tparameters [ id=\"{code}\" ]"
                + RIM_LINE_SEP
                + "\t}"));
    assertTrue(
        generator.generatedRimDsl.contains(
            "GET -> passenger_flight {"
                + RIM_LINE_SEP
                + "\t\ttitle: \"flight\""
                + RIM_LINE_SEP
                + "\t\tparameters [ id=\"{passengerNo}\" ]"
                + RIM_LINE_SEP
                + "\t}"));
  }
Exemplo n.º 2
0
  @Test
  public void testGetRIM() {
    // Parse the test metadata
    MetadataParser parser = new MetadataParser();
    InputStream is =
        parser.getClass().getClassLoader().getResourceAsStream(METADATA_AIRLINE_XML_FILE);
    Metadata metadata = parser.parse(is);
    Assert.assertNotNull(metadata);

    // Define the interaction model
    InteractionModel interactionModel = new InteractionModel(metadata);

    IMResourceStateMachine rsmFlightSchedule =
        interactionModel.findResourceStateMachine("FlightSchedule");
    IMResourceStateMachine rsmAirport = interactionModel.findResourceStateMachine("Airport");
    IMResourceStateMachine rsmFlight = interactionModel.findResourceStateMachine("Flight");
    IMResourceStateMachine rsmPassenger = interactionModel.findResourceStateMachine("Passenger");
    rsmFlight.addTransitionToEntityState(
        "flight", rsmFlightSchedule, "flightschedule", "flightScheduleNum", null);
    rsmFlightSchedule.addTransitionToEntityState(
        "flightschedule", rsmAirport, "departureAirport", "departureAirportCode", null);
    rsmFlightSchedule.addTransitionToEntityState(
        "flightschedule", rsmAirport, "arrivalAirport", "arrivalAirportCode", null);
    rsmAirport.addTransitionToCollectionState(
        "airport",
        rsmFlightSchedule,
        "departures",
        "departureAirportCode eq '{code}'",
        "departureAirportCode",
        null);
    rsmAirport.addTransitionToCollectionState(
        "airport",
        rsmFlightSchedule,
        "arrivals",
        "arrivalAirportCode eq '{code}'",
        "arrivalAirportCode",
        null);
    rsmPassenger.addTransitionToEntityState("passenger", rsmFlight, "flight", "flightID", null);

    // Run the generator
    JPAResponderGen generator = new JPAResponderGen(true);
    Commands commands = JPAResponderGen.getDefaultCommands();
    String rimDSL = null;
    try {
      InputStream isRimDsl = generator.getRIM(interactionModel, commands);
      assertNotNull(isRimDsl);

      rimDSL = CharStreams.toString(new InputStreamReader(isRimDsl, "UTF-8"));
    } catch (Exception age) {
      fail(age.getMessage());
    }

    // Check the rim dsl
    assertTrue(rimDSL.contains("initial resource ServiceDocument"));
    assertTrue(rimDSL.contains("GET -> FlightSchedules"));
    assertTrue(rimDSL.contains("resource FlightSchedules"));
    assertTrue(
        rimDSL.contains(
            "GET *-> flightschedule {"
                + RIM_LINE_SEP
                + "\t\tparameters [ id=\"{flightScheduleID}\" ]"
                + RIM_LINE_SEP
                + "\t}"));
    assertTrue(
        rimDSL.contains(
            "GET *-> flightschedule_departureAirport {"
                + RIM_LINE_SEP
                + "\t\tparameters [ id=\"{flightScheduleID}\" ]"
                + RIM_LINE_SEP
                + "\t}"));
    assertTrue(rimDSL.contains("resource flightschedule_departureAirport"));
    assertTrue(rimDSL.contains("path: \"/FlightSchedules({id})/departureAirport\""));
    assertTrue(rimDSL.contains("GET -> Passengers"));
    assertTrue(rimDSL.contains("resource Passengers"));
  }
Exemplo n.º 3
0
  @Test
  public void testGeneratedArtifactsFromConceptualModels() {
    // Parse the test metadata
    MetadataParser parser = new MetadataParser();
    InputStream is =
        parser.getClass().getClassLoader().getResourceAsStream(METADATA_AIRLINE_XML_FILE);
    Metadata metadata = parser.parse(is);
    Assert.assertNotNull(metadata);

    // Define the interaction model
    InteractionModel interactionModel = new InteractionModel(metadata);

    IMResourceStateMachine rsmFlightSchedule =
        interactionModel.findResourceStateMachine("FlightSchedule");
    IMResourceStateMachine rsmAirport = interactionModel.findResourceStateMachine("Airport");
    IMResourceStateMachine rsmFlight = interactionModel.findResourceStateMachine("Flight");
    IMResourceStateMachine rsmPassenger = interactionModel.findResourceStateMachine("Passenger");
    rsmFlight.addTransitionToEntityState(
        "flight", rsmFlightSchedule, "flightschedule", "flightScheduleNum", null);
    rsmFlightSchedule.addTransitionToEntityState(
        "flightschedule", rsmAirport, "departureAirport", "departureAirportCode", null);
    rsmFlightSchedule.addTransitionToEntityState(
        "flightschedule", rsmAirport, "arrivalAirport", "arrivalAirportCode", null);
    rsmAirport.addTransitionToCollectionState(
        "airport",
        rsmFlightSchedule,
        "departures",
        "departureAirportCode eq '{code}'",
        "departureAirportCode",
        null);
    rsmAirport.addTransitionToCollectionState(
        "airport",
        rsmFlightSchedule,
        "arrivals",
        "arrivalAirportCode eq '{code}'",
        "arrivalAirportCode",
        null);
    rsmPassenger.addTransitionToEntityState("passenger", rsmFlight, "flight", "flightID", null);

    // Run the generator
    MockGenerator generator = new MockGenerator();
    boolean status =
        generator.generateArtifacts(
            metadata,
            interactionModel,
            new File("target/FlightResponder/classes"),
            new File("target/FlightResponder/classes"),
            true);

    // Check results
    assertTrue(status);

    assertTrue(generator.generatedClasses.size() == 4);
    assertTrue(generator.generatedClasses.get(0).contains("public class Flight"));
    assertTrue(generator.generatedClasses.get(1).contains("public class Airport"));
    assertTrue(generator.generatedClasses.get(2).contains("public class FlightSchedule"));
    assertTrue(generator.generatedClasses.get(3).contains("public class Passenger"));

    assertTrue(generator.generateResponderDML.contains("INSERT INTO `Flight`("));
    assertTrue(generator.generateResponderDML.contains("INSERT INTO `Airport`("));
    assertTrue(generator.generateResponderDML.contains("INSERT INTO `FlightSchedule`("));
    assertTrue(generator.generateResponderDML.contains("INSERT INTO `Passenger`("));

    assertTrue(
        generator.generatedPersistenceXML.contains("<class>FlightResponderModel.Flight</class>"));
    assertTrue(
        generator.generatedPersistenceXML.contains("<class>FlightResponderModel.Airport</class>"));
    assertTrue(
        generator.generatedPersistenceXML.contains(
            "<class>FlightResponderModel.FlightSchedule</class>"));
    assertTrue(
        generator.generatedPersistenceXML.contains(
            "<class>FlightResponderModel.Passenger</class>"));

    assertTrue(
        generator.generatedSpringXML.contains(
            "<bean id=\"behaviour\" class=\"FlightResponderModel.FlightResponderBehaviour\" />"));

    assertTrue(
        generator.generatedSpringResourceManagerXML.contains(
            "<constructor-arg name=\"namespace\" value=\"FlightResponder\" />"));

    // Test rim dsl
    assertTrue(generator.generatedRimDsl.contains("initial resource ServiceDocument"));
    assertTrue(generator.generatedRimDsl.contains("GET -> FlightSchedules"));
    assertTrue(generator.generatedRimDsl.contains("resource FlightSchedules"));
    assertTrue(
        generator.generatedRimDsl.contains(
            "GET *-> flightschedule {"
                + RIM_LINE_SEP
                + "\t\tparameters [ id=\"{flightScheduleID}\" ]"
                + RIM_LINE_SEP
                + "\t}"));
    assertTrue(
        generator.generatedRimDsl.contains(
            "GET *-> flightschedule_departureAirport {"
                + RIM_LINE_SEP
                + "\t\tparameters [ id=\"{flightScheduleID}\" ]"
                + RIM_LINE_SEP
                + "\t}"));
    assertTrue(generator.generatedRimDsl.contains("resource flightschedule_departureAirport"));
    assertTrue(
        generator.generatedRimDsl.contains("path: \"/FlightSchedules({id})/departureAirport\""));
    assertTrue(generator.generatedRimDsl.contains("GET -> Passengers"));
    assertTrue(generator.generatedRimDsl.contains("resource Passengers"));
  }