@Test
  public void testTidyServiceDescriptions() {
    Object expression = null;

    try {
      java.io.InputStream is =
          Thread.currentThread().getContextClassLoader().getResourceAsStream(SCRIPT);

      if (is == null) {
        fail("Unable to locate '" + SCRIPT + "'");
      } else {
        byte[] b = new byte[is.available()];
        is.read(b);
        is.close();

        // Compile expression
        expression = MVEL.compileExpression(new String(b));
      }
    } catch (Exception e) {
      fail("Failed to test script: " + e);
    }

    java.util.Map<String, Object> vars = new java.util.HashMap<String, Object>();

    java.util.Map<String, Object> internalVariables = new java.util.HashMap<String, Object>();

    ActiveCollectionSource acs = new ActiveCollectionSource();

    acs.getProperties().put("maxSnapshots", 3);

    ActiveMap map = new ActiveMap("TestMap");

    acs.setActiveCollection(map);

    // Add some service definitions
    ServiceDefinition sd1 = new ServiceDefinition();
    sd1.setServiceType("sd1");
    acs.insert(sd1.getServiceType(), sd1);

    ServiceDefinition sd2 = new ServiceDefinition();
    sd2.setServiceType("sd2");
    acs.insert(sd2.getServiceType(), sd2);

    vars.put("acs", acs);
    vars.put("variables", internalVariables);

    MVEL.executeExpression(expression, vars);

    @SuppressWarnings("unchecked")
    java.util.List<Object> snapshots = (List<Object>) internalVariables.get("snapshots");

    if (snapshots == null) {
      fail("No snapshots recorded");
    }

    if (snapshots.size() != 1) {
      fail("Expecting 1 snapshot: " + snapshots.size());
    }

    MVEL.executeExpression(expression, vars);

    if (snapshots.size() != 2) {
      fail("Expecting 2 snapshot: " + snapshots.size());
    }

    MVEL.executeExpression(expression, vars);

    if (snapshots.size() != 3) {
      fail("Expecting 3 snapshot: " + snapshots.size());
    }

    // Need to check that only three snapshots (as defined
    // by the cleanup cycle) will be retained
    MVEL.executeExpression(expression, vars);

    if (snapshots.size() != 3) {
      fail("Expecting 3 snapshot: " + snapshots.size());
    }
  }
Пример #2
0
  @Test
  public void highGround() {
    this.addDeck(
        HighGround.class,
        WhiteKnight.class,
        Plains.class,
        Plains.class,
        Plains.class,
        Plains.class,
        Plains.class);
    this.addDeck(
        RagingGoblin.class,
        RagingGoblin.class,
        RagingGoblin.class,
        Plains.class,
        Plains.class,
        Plains.class,
        Plains.class,
        Plains.class);
    this.startGame(GameTypes.OPEN);

    this.respondWith(this.getPlayer(0));
    this.keep();
    this.keep();

    this.goToPhase(Phase.PhaseType.PRECOMBAT_MAIN);

    this.respondWith(this.getSpellAction(WhiteKnight.class));
    this.addMana("WW");
    this.donePlayingManaAbilities();
    this.pass();
    this.pass();

    this.respondWith(this.getSpellAction(HighGround.class));
    this.addMana("W");
    this.donePlayingManaAbilities();
    this.pass();
    this.pass();

    this.goToPhase(Phase.PhaseType.ENDING);
    this.goToPhase(Phase.PhaseType.PRECOMBAT_MAIN);

    this.respondWith(this.getSpellAction(RagingGoblin.class));
    this.addMana("R");
    this.donePlayingManaAbilities();
    this.pass();
    this.pass();
    Identified RagingGoblinA = this.game.physicalState.battlefield().objects.get(0);

    this.respondWith(this.getSpellAction(RagingGoblin.class));
    this.addMana("R");
    this.donePlayingManaAbilities();
    this.pass();
    this.pass();
    Identified RagingGoblinB = this.game.physicalState.battlefield().objects.get(0);

    this.respondWith(this.getSpellAction(RagingGoblin.class));
    this.addMana("R");
    this.donePlayingManaAbilities();
    this.pass();
    this.pass();
    Identified RagingGoblinC = this.game.physicalState.battlefield().objects.get(0);

    this.goToStep(Step.StepType.DECLARE_ATTACKERS);
    this.respondWith(
        this.getChoice(RagingGoblinA),
        this.getChoice(RagingGoblinB),
        this.getChoice(RagingGoblinC));

    this.goToStep(Step.StepType.DECLARE_BLOCKERS);
    this.respondWith(this.pullChoice(WhiteKnight.class));
    this.respondWith(this.getChoice(RagingGoblinA), this.getChoice(RagingGoblinB));
    this.respondArbitrarily();

    this.goToStep(Step.StepType.COMBAT_DAMAGE);
    java.util.Map<Integer, Integer> divisions = new java.util.HashMap<Integer, Integer>();
    divisions.put(RagingGoblinA.ID, 1);
    divisions.put(RagingGoblinB.ID, 1);
    this.divide(divisions);
    // order the goblins in the yard

    this.goToPhase(Phase.PhaseType.POSTCOMBAT_MAIN);
    assertEquals(19, this.player(0).lifeTotal);
    // one goblin, high ground, white knight
    assertEquals(3, this.game.actualState.battlefield().objects.size());
  }
Пример #3
0
  @Test
  public void testOutOfStock() {
    // Conversation manager must be sharable, as could be specific to
    // conversation engine, but may also be based on a persistent
    // central repository
    ConversationManager cm = new DefaultConversationManager();
    DefaultParticipantRegistry pr = new DefaultParticipantRegistry();
    DefaultMessagingLayer ml = new DefaultMessagingLayer();

    java.security.Principal gary = new KerberosPrincipal("*****@*****.**");

    pr.addParticipant(new DefaultParticipant(PurchasingSeller.INSTANCE.getRole(), gary));
    pr.addParticipant(new DefaultParticipant(PurchasingCreditAgency.INSTANCE.getRole(), gary));

    DefaultConversationEngine ce1 = new DefaultConversationEngine();

    Set<ConversationType> cts1 = new HashSet<ConversationType>();
    cts1.add(PurchasingBuyer.INSTANCE);
    cts1.add(PurchasingSeller.INSTANCE);
    ce1.setConversationTypes(cts1);

    ce1.setPrincipal(gary);
    ce1.setConversationManager(cm);
    ce1.setParticipantRegistry(pr);
    ce1.setMessagingLayer(ml);

    ml.init(ce1);

    TestListener tl1 = new TestListener("ce1");

    ce1.setListener(tl1);

    DefaultConversationEngine ce2 = new DefaultConversationEngine();

    Set<ConversationType> cts2 = new HashSet<ConversationType>();
    cts2.add(PurchasingCreditAgency.INSTANCE);
    ce2.setConversationTypes(cts2);

    ce2.setPrincipal(gary);
    ce2.setConversationManager(cm);
    ce2.setParticipantRegistry(pr);
    ce2.setMessagingLayer(ml);

    ml.init(ce2);

    TestListener tl2 = new TestListener("ce2");

    ce2.setListener(tl2);

    ConversationId cid = new DefaultConversationId("1");

    java.util.Map<String, Object> vars = new java.util.HashMap<String, Object>();
    vars.put("product", "car");
    vars.put("price", 150);

    ce1.createConversation(cid, PurchasingBuyer.INSTANCE, vars);

    if (tl1.getStartedCount() != 2) {
      fail("Start count should be 2: " + tl1.getStartedCount());
    }

    if (tl1.getSendingCount() != 2) {
      fail("Sending count should be 2: " + tl1.getSendingCount());
    }

    if (tl1.getReceivedCount() != 2) {
      fail("Received count should be 2: " + tl1.getReceivedCount());
    }

    if (tl1.getFinishedCount() != 2) {
      fail("Finished count should be 2: " + tl1.getFinishedCount());
    }

    if (tl2.getStartedCount() != 0) {
      fail("Start count should be 0: " + tl2.getStartedCount());
    }

    if (tl2.getSendingCount() != 0) {
      fail("Sending count should be 0: " + tl2.getSendingCount());
    }

    if (tl2.getReceivedCount() != 0) {
      fail("Received count should be 0: " + tl2.getReceivedCount());
    }

    if (tl2.getFinishedCount() != 0) {
      fail("Finished count should be 0: " + tl2.getFinishedCount());
    }
  }