private BusinessObjectService getMockBusinessObjectService() {
    final BusinessObjectService service = context.mock(BusinessObjectService.class);

    context.checking(
        new Expectations() {
          {
            Map<String, Object> fieldValues1 = new HashMap<String, Object>();
            fieldValues1.put(REL_TYPE_SORT_ID_FIELD_NAME, SORT_ID_1);
            //           fieldValues1.put(GROUP_NAME_FIELD_NAME, GROUP_NAME);

            FinIntEntityRelType finIntEntityRelType = new FinIntEntityRelType();
            finIntEntityRelType.setRelationshipTypeCode(CODE_1);

            allowing(service).findMatching(FinIntEntityRelType.class, fieldValues1);
            will(returnValue(Collections.singleton(finIntEntityRelType)));
          }
        });

    context.checking(
        new Expectations() {
          {
            Map<String, String> fieldValues = new HashMap<String, String>();
            fieldValues.put(DESCRIPTION_FIELD_NAME, DESCRIPTION_1);
            FinIntEntityRelType finIntEntityRelType = new FinIntEntityRelType();
            finIntEntityRelType.setRelationshipTypeCode(CODE_1);

            allowing(service).findMatching(FinIntEntityRelType.class, fieldValues);
            will(returnValue(Collections.singleton(finIntEntityRelType)));
          }
        });

    return service;
  }
Пример #2
0
  public void testDoesNotAssignPassiveLeafIfDisabled() throws Exception {
    ConnectionSettings.EVER_ACCEPTED_INCOMING.setValue(true);
    DHTSettings.ENABLE_PASSIVE_LEAF_DHT_MODE.setValue(false);
    long startTime =
        System.currentTimeMillis() - DHTSettings.MIN_PASSIVE_LEAF_DHT_INITIAL_UPTIME.getValue();
    PrivilegedAccessor.setValue(nodeAssigner, "startTime", new Long(startTime));

    mockery.checking(buildBandwdithExpectations(true));
    mockery.checking(
        buildDHTExpectations(
            DHTMode.INACTIVE,
            true,
            true,
            false, // can't receive unsolicited
            DHTSettings.MIN_PASSIVE_LEAF_DHT_AVERAGE_UPTIME.getValue() + 1,
            false,
            false));

    mockery.checking(
        new Expectations() {
          {
            never(dhtManager).start(with(Matchers.any(DHTMode.class)));
          }
        });

    assignerRunnable.run();
    mockery.assertIsSatisfied();
  }
Пример #3
0
  public void testPassiveLeafDoesNotNeedHardCore() throws Exception {
    // not accepted incoming previously therefore not hardcore
    long startTime =
        System.currentTimeMillis() - DHTSettings.MIN_PASSIVE_LEAF_DHT_INITIAL_UPTIME.getValue();
    PrivilegedAccessor.setValue(nodeAssigner, "startTime", new Long(startTime));

    mockery.checking(buildBandwdithExpectations(true));
    mockery.checking(
        buildDHTExpectations(
            DHTMode.INACTIVE,
            true,
            true,
            false, // can't receive unsolicited
            DHTSettings.MIN_PASSIVE_LEAF_DHT_AVERAGE_UPTIME.getValue() + 1,
            false,
            false));

    mockery.checking(
        new Expectations() {
          {
            one(dhtManager).start(DHTMode.PASSIVE_LEAF);
          }
        });

    assignerRunnable.run();
    mockery.assertIsSatisfied();
  }
Пример #4
0
  public void testStopsDHTWhenDisabled() throws Exception {
    ConnectionSettings.EVER_ACCEPTED_INCOMING.setValue(true);
    long startTime =
        System.currentTimeMillis() - DHTSettings.MIN_ACTIVE_DHT_INITIAL_UPTIME.getValue();
    PrivilegedAccessor.setValue(nodeAssigner, "startTime", new Long(startTime));

    mockery.checking(buildBandwdithExpectations(true));
    mockery.checking(
        buildDHTExpectations(
            DHTMode.ACTIVE,
            false,
            true,
            true,
            DHTSettings.MIN_ACTIVE_DHT_AVERAGE_UPTIME.getValue() + 1,
            false,
            false));

    mockery.checking(
        new Expectations() {
          {
            one(dhtManager).stop();
          }
        });

    assignerRunnable.run();
    mockery.assertIsSatisfied();
  }
Пример #5
0
  public void testDoesNotAssignLowInitialUptime() throws Exception {
    ConnectionSettings.EVER_ACCEPTED_INCOMING.setValue(true);

    // no initial uptime
    mockery.checking(buildBandwdithExpectations(true));
    mockery.checking(
        buildDHTExpectations(
            DHTMode.INACTIVE,
            true,
            true,
            true,
            DHTSettings.MIN_ACTIVE_DHT_AVERAGE_UPTIME.getValue() + 1,
            false,
            false));

    mockery.checking(
        new Expectations() {
          {
            never(dhtManager).start(with(Matchers.any(DHTMode.class)));
          }
        });

    assignerRunnable.run();
    mockery.assertIsSatisfied();
  }
Пример #6
0
  public void testDoesNotAssignLowAverageUptime() throws Exception {
    ConnectionSettings.EVER_ACCEPTED_INCOMING.setValue(true);
    long startTime =
        System.currentTimeMillis() - DHTSettings.MIN_ACTIVE_DHT_INITIAL_UPTIME.getValue();
    PrivilegedAccessor.setValue(nodeAssigner, "startTime", new Long(startTime));

    mockery.checking(buildBandwdithExpectations(true));
    mockery.checking(
        buildDHTExpectations(
            DHTMode.INACTIVE,
            true,
            true,
            true,
            0, // no average uptime
            false,
            false));

    mockery.checking(
        new Expectations() {
          {
            never(dhtManager).start(with(Matchers.any(DHTMode.class)));
          }
        });

    assignerRunnable.run();
    mockery.assertIsSatisfied();
  }
Пример #7
0
 /**
  * Returns:
  *
  * <ul>
  *   <li>{@code null} if this engine is marked as closed, or if current action is not one of
  *       {@link HandshakeAction#NEED_TASK NEED_TASK}, {@link HandshakeAction#NEED_FAULTY_TASK
  *       NEED_FAULTY_TASK}.
  *   <li>a task mock if current action is {@link HandshakeAction#NEED_TASK NEED_TASK}. The mock
  *       expects to have its method {@code run()} invoked exactly once by client
  *   <li>a task mock whose {@code run()} method will throw an exception, if current action is
  *       {@link HandshakeAction#NEED_FAULTY_TASK NEED_FAULTY_TASK}. The mock expects to have its
  *       method {@code run()} invoked exactly once.
  * </ul>
  */
 @SuppressWarnings("incomplete-switch")
 @Override
 public synchronized Runnable getDelegatedTask() {
   if (!closed && actionIndex < actions.length) {
     switch (actions[actionIndex]) {
       case NEED_TASK:
         {
           actionIndex++;
           synchronized (mockery) {
             final Runnable task = mockery.mock(Runnable.class, "RunnableMock" + taskCount++);
             mockery.checking(
                 new Expectations() {
                   {
                     oneOf(task).run();
                   }
                 });
             return task;
           }
         }
       case NEED_FAULTY_TASK:
         synchronized (mockery) {
           final Runnable task = mockery.mock(Runnable.class, "RunnableFaultyMock" + taskCount++);
           mockery.checking(
               new Expectations() {
                 {
                   oneOf(task).run();
                   will(throwException(new RuntimeException()));
                 }
               });
           return task;
         }
     }
   }
   return null;
 }
Пример #8
0
 @Override
 public SSLSession getSession() {
   synchronized (mockery) {
     final SSLSession sessionMock = mockery.mock(SSLSession.class, "Session" + sessionCount++);
     if (sessionCount == 1) {
       mockery.checking(
           new Expectations() {
             {
               oneOf(sessionMock).getPacketBufferSize();
               will(returnValue(16916));
               oneOf(sessionMock).getApplicationBufferSize();
               will(returnValue(16921));
             }
           });
     } else {
       mockery.checking(
           new Expectations() {
             {
               allowing(sessionMock).getPacketBufferSize();
               will(returnValue(16916));
               allowing(sessionMock).getApplicationBufferSize();
               will(returnValue(16921));
             }
           });
     }
     return sessionMock;
   }
 }
Пример #9
0
 @Before
 protected void setUp() throws Exception {
   Mockery contractServiceMockery = new Mockery();
   final IContractService contractService = contractServiceMockery.mock(IContractService.class);
   contractServiceMockery.checking(
       new Expectations() {
         {
           allowing(contractService).searchOperaLogByWorkflowId("1");
           List<ContractOperatorLog> contractLogList = new ArrayList<ContractOperatorLog>();
           ContractOperatorLog c = new ContractOperatorLog();
           c.setCreateUser("1");
           contractLogList.add(c);
           will(returnValue(contractLogList));
         }
       });
   contractWorkflowManager.setContractService(contractService);
   Mockery contractWorkflowServiceMockery = new Mockery();
   final IContractWorkflowService contractWorkflowService =
       contractWorkflowServiceMockery.mock(IContractWorkflowService.class);
   contractWorkflowServiceMockery.checking(
       new Expectations() {
         {
           allowing(contractWorkflowService)
               .queryContractWorkflowInfoByBusino(with(any(String.class)));
           will(returnValue(new ContractWorkflowInfo()));
         }
       });
   contractWorkflowManager.setContractWorkflowService(contractWorkflowService);
   Mockery employeeServiceMockery = new Mockery();
   final IEmployeeService employeeService = employeeServiceMockery.mock(IEmployeeService.class);
   employeeServiceMockery.checking(
       new Expectations() {
         {
           allowing(employeeService).getEmpById("1");
           Employee employee = new Employee();
           employee.setEmpCode("1");
           will(returnValue(employee));
         }
       });
   contractWorkflowManager.setEmployeeService(employeeService);
   Mockery userServiceMockery = new Mockery();
   final IUserService userService = userServiceMockery.mock(IUserService.class);
   userServiceMockery.checking(
       new Expectations() {
         {
           allowing(userService).findByLoginName("1");
           User user = new User();
           user.setId("1");
           will(returnValue(user));
           allowing(userService).getUserRoleFunDeptById("1");
           will(returnValue(user));
         }
       });
   contractWorkflowManager.setUserService(userService);
 }
Пример #10
0
  public void testDoesNotPromoteIfNoUDP() throws Exception {
    ConnectionSettings.EVER_ACCEPTED_INCOMING.setValue(true);
    ApplicationSettings.AVERAGE_UPTIME.setValue(UltrapeerSettings.MIN_AVG_UPTIME.getValue() + 1);
    assertFalse(UltrapeerSettings.EVER_ULTRAPEER_CAPABLE.getValue());

    mockery.checking(buildBandwdithExpectations(true));
    // no UDP support
    mockery.checking(buildUltrapeerExpectations(false, true, 0l, false, DHTMode.INACTIVE, false));
    // will not get promoted
    mockery.checking(buildPromotionExpectations(false));
    assignerRunnable.run();
    assertFalse(UltrapeerSettings.EVER_ULTRAPEER_CAPABLE.getValue());
    mockery.assertIsSatisfied();
  }
Пример #11
0
  public void testDoesNotPromoteModemSpeed() throws Exception {
    ConnectionSettings.EVER_ACCEPTED_INCOMING.setValue(true);
    ApplicationSettings.AVERAGE_UPTIME.setValue(UltrapeerSettings.MIN_AVG_UPTIME.getValue() + 1);
    assertFalse(UltrapeerSettings.EVER_ULTRAPEER_CAPABLE.getValue());

    // everything else fine
    // setting up bad bandwidth to simulate a modem speed
    mockery.checking(buildBandwdithExpectations(false));
    mockery.checking(buildUltrapeerExpectations(true, true, 0l, false, DHTMode.INACTIVE, false));
    mockery.checking(buildPromotionExpectations(false));

    assignerRunnable.run();
    assertFalse(UltrapeerSettings.EVER_ULTRAPEER_CAPABLE.getValue());
    mockery.assertIsSatisfied();
  }
Пример #12
0
  public void testPromotesUltrapeer() throws Exception {
    ConnectionSettings.EVER_ACCEPTED_INCOMING.setValue(true);
    ApplicationSettings.AVERAGE_UPTIME.setValue(UltrapeerSettings.MIN_AVG_UPTIME.getValue() + 1);
    assertFalse(UltrapeerSettings.EVER_ULTRAPEER_CAPABLE.getValue());

    // set up some conditions for ultrapeer-ness
    // all of them are required
    mockery.checking(buildBandwdithExpectations(true));
    mockery.checking(buildUltrapeerExpectations(true, true, 0l, false, DHTMode.INACTIVE, true));
    mockery.checking(buildPromotionExpectations(true));

    assignerRunnable.run();
    assertTrue(UltrapeerSettings.EVER_ULTRAPEER_CAPABLE.getValue());
    mockery.assertIsSatisfied();
  }
Пример #13
0
  public static AttributeInterface createAttribute(
      final String name, final EntityInterface entity, final TermType termType) {
    final AttributeTypeInformationInterface attrInfo;
    switch (termType) {
      case Numeric:
        attrInfo = context.mock(NumericTypeInformationInterface.class, getI());
        break;
      case Date:
        attrInfo = context.mock(DateTypeInformationInterface.class, getI());
        context.checking(
            new Expectations() {
              {
                allowing((DateTypeInformationInterface) attrInfo).getFormat();
                will(returnValue("foo"));
              }
            });
        break;
      case Timestamp:
        attrInfo = context.mock(DateTypeInformationInterface.class, getI());
        context.checking(
            new Expectations() {
              {
                allowing((DateTypeInformationInterface) attrInfo).getFormat();
                will(returnValue("MM-dd-yyyy HH:mm"));
              }
            });
        break;
      case String:
        attrInfo = context.mock(StringTypeInformationInterface.class, getI());
        break;
      default:
        throw new IllegalArgumentException();
    }
    final AttributeInterface attribute = context.mock(AttributeInterface.class, getI());

    context.checking(
        new Expectations() {
          {
            allowing(attribute).getName();
            will(returnValue(name));
            allowing(attribute).getEntity();
            will(returnValue(entity));
            allowing(attribute).getAttributeTypeInformation();
            will(returnValue(attrInfo));
          }
        });
    return attribute;
  }
Пример #14
0
  @Test
  public void shouldLogMessageIndicatingFailedHeaderMatch() {
    context.checking(
        new Expectations() {
          {
            one(notifier)
                .info(
                    "URL /for/logging is match, but header Content-Type is not. For a match, value should equal text/xml");
          }
        });

    RequestPattern requestPattern = new RequestPattern(POST, "/for/logging");
    ValuePattern headerPattern = new ValuePattern();
    headerPattern.setEqualTo("text/xml");
    requestPattern.addHeader("Content-Type", headerPattern);

    Request request =
        aRequest(context)
            .withUrl("/for/logging")
            .withMethod(POST)
            .withHeader("Content-Type", "text/plain")
            .build();

    requestPattern.isMatchedBy(request);
  }
Пример #15
0
  @Test
  public void deleteExpectSuccess() {
    context.checking(
        new Expectations() {
          {
            Avatar s1 = new Avatar();
            s1.setId(1);
            s1.setFileName(Long.toString(System.currentTimeMillis()));
            Avatar s2 = new Avatar();
            s2.setId(2);
            s2.setFileName(Long.toString(System.currentTimeMillis()));

            String applicationPath =
                new File(this.getClass().getResource("").getFile()).getParent();

            atLeast(1).of(config).getApplicationPath();
            will(returnValue(applicationPath));
            atLeast(1).of(config).getValue(ConfigKeys.AVATAR_GALLERY_DIR);
            will(returnValue(""));

            one(repository).get(1);
            will(returnValue(s1));
            one(repository).remove(s1);

            one(repository).get(2);
            will(returnValue(s2));
            one(repository).remove(s2);
          }
        });

    service.delete(1, 2);
    context.assertIsSatisfied();
  }
 @SuppressWarnings("unchecked")
 protected ParameterService getParameterService() {
   final ParameterService parameterService = context.mock(ParameterService.class);
   context.checking(
       new Expectations() {
         {
           allowing(parameterService)
               .parameterExists(with(any(Class.class)), with(any(String.class)));
           will(returnValue(true));
           allowing(parameterService)
               .getParameterValueAsBoolean(
                   ProtocolDocument.class, Constants.ENABLE_PROTOCOL_TO_AWARD_LINK);
           will(returnValue(true));
           allowing(parameterService)
               .getParameterValueAsBoolean(
                   ProtocolDocument.class, Constants.ENABLE_PROTOCOL_TO_DEV_PROPOSAL_LINK);
           will(returnValue(true));
           allowing(parameterService)
               .getParameterValueAsBoolean(
                   ProtocolDocument.class, Constants.ENABLE_PROTOCOL_TO_PROPOSAL_LINK);
           will(returnValue(true));
         }
       });
   return parameterService;
 }
  protected FundingSourceTypeService getFundingSourceTypeService() {
    final FundingSourceTypeService service = context.mock(FundingSourceTypeService.class);
    context.checking(
        new Expectations() {
          {
            allowing(service).getFundingSourceType(SPONSOR_SOURCE_TYPE_ID);
            will(returnValue(fundingSponsorSourceType));

            allowing(service).getFundingSourceType(UNIT_SOURCE_TYPE_ID);
            will(returnValue(fundingUnitSourceType));

            allowing(service).getFundingSourceType(OTHER_SOURCE_TYPE_ID);
            will(returnValue(fundingOtherSourceType));

            allowing(service).getFundingSourceType(DEVELOPMENT_PROP_SOURCE_TYPE_ID);
            will(returnValue(fundingDevProposalSourceType));

            allowing(service).getFundingSourceType(INSTITUTE_PROP_SOURCE_TYPE_ID);
            will(returnValue(fundingInstProposalSourceType));

            allowing(service).getFundingSourceType(AWARD_SOURCE_TYPE_ID);
            will(returnValue(fundingAwardSourceType));
          }
        });
    return service;
  }
 @Test
 public void removing_all_items_from_a_location_removes_TakeAnItem_action_from_action_list() {
   final Item takeableItem = mockery.mock(Item.class);
   final ActionFactory actionFactory = mockery.mock(ActionFactory.class);
   final Location l = new Location("", "", null, actionFactory);
   mockery.checking(
       new Expectations() {
         {
           allowing(takeableItem).visible();
           will(returnValue(true));
           allowing(takeableItem).takeable();
           will(returnValue(true));
           ignoring(takeableItem);
           never(actionFactory)
               .createTakeAnItemAction(
                   with(any(List.class)),
                   with(any(UserInventory.class)),
                   with(any(ModelLocation.class)));
           ignoring(actionFactory);
         }
       });
   l.addItem(takeableItem);
   l.removeItem(takeableItem);
   l.actions();
 }
Пример #19
0
  @Test
  public void exceptionInProtocolClosesClientSession() throws IOException {
    i = 0;
    final Protocol protocol =
        new Protocol() {
          public void init(ClientSession session) {}

          public void parseFirst(InputStream message) throws IOException {}

          public void parsePacket(InputStream message) throws IOException {
            i++;
            throw new IOException("Test");
          }
        };

    context.checking(
        new Expectations() {
          {
            oneOf(mockedClient).close();
          }
        });

    prot.setCurrentProtocol(protocol);

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    CData.writeU16(out, 2);
    CData.writeU16(out, 1337);
    prot.messageReceived(mockedClient, new ByteArrayInputStream(out.toByteArray()));

    assertEquals(1, i);

    context.assertIsSatisfied();
  }
  @Test
  public void actions_uses_action_factory_to_create_ExamineAnItem_action_for_all_visible_items() {
    final Item visibleItem = mockery.mock(Item.class, "visible item");
    final Item invisibleItem = mockery.mock(Item.class, "invisible item");
    final ActionFactory actionFactory = mockery.mock(ActionFactory.class);
    final Action examineAnItemAction = mockery.mock(Action.class);
    final List<Item> visibleItems = new ArrayList<Item>();
    visibleItems.add(visibleItem);
    mockery.checking(
        new Expectations() {
          {
            allowing(visibleItem).visible();
            will(returnValue(true));
            ignoring(visibleItem);
            allowing(invisibleItem).visible();
            will(returnValue(false));
            ignoring(invisibleItem);
            oneOf(actionFactory).createExamineAnItemAction(with(equal(visibleItems)));
            will(returnValue(examineAnItemAction));
            ignoring(actionFactory);
          }
        });
    Location l = new Location("", "", null, actionFactory);
    l.addItem(visibleItem);
    l.addItem(invisibleItem);

    List<Action> actions = l.actions();
    assertTrue(actions.size() > 0);
    assertThat(actions.get(0), is(examineAnItemAction));
  }
Пример #21
0
  @Test
  public void testOneSubscriberReceivesAMessage() {

    final Subscriber subscriber = context.mock(Subscriber.class);
    final String message = "message";
    context.checking(
        new Expectations() {
          {
            // never(subscriber).receive(message);
            oneOf(subscriber).receive(message);
            // exactly(1).of(subscriber).receive(message);
            // atLeast(1).of(subscriber).receive(message);
            // atMost(2).of(subscriber).receive(message);
            // between(1, 5).of(subscriber).receive(message);
            // allowing(subscriber).receive(message);
            will(returnValue("Hello world"));
          }
        });

    Publisher publisher = new Publisher();
    publisher.add(subscriber);
    // execute
    String answer = publisher.publish(message);
    // verify
    context.assertIsSatisfied();
    Assert.assertEquals("Hello world", answer);
  }
  /**
   * Tests execute with a notifier exception (for coverage).
   *
   * @throws Exception Shouldn't.
   */
  @Test
  @SuppressWarnings("unchecked")
  public void testExecuteNotifierError() throws Exception {
    final List<Long> recipients = Collections.singletonList(4L);
    final NotificationDTO notification =
        new NotificationDTO(
            recipients, NotificationType.FOLLOW_PERSON, 1L, 2L, EntityType.PERSON, 3L);

    context.checking(
        new Expectations() {
          {
            oneOf(followerTranslator).translate(1, 2, 3);
            will(returnValue(Collections.singletonList(notification)));

            allowing(personMapper).execute(with(equal(4L)));
            will(returnValue(person));

            oneOf(populator).populate(with(same(notification)));

            oneOf(preferencesMapper).execute(with(any(List.class)));
            will(returnValue(new ArrayList<NotificationFilterPreferenceDTO>()));

            oneOf(applicationNotifier).notify(with(any(NotificationDTO.class)));
            will(returnValue(null));
            oneOf(emailNotifier).notify(with(any(NotificationDTO.class)));
            will(throwException(new Exception("BAD")));
          }
        });

    CreateNotificationsRequest request =
        new CreateNotificationsRequest(RequestType.FOLLOWER, 1, 2, 3);
    sut.execute(TestContextCreator.createTaskHandlerAsyncContext(request));
    context.assertIsSatisfied();
  }
  @Test
  public void all_valid_exits_are_retrieveable() {
    final Exit exit1 = mockery.mock(Exit.class, "exit1");
    final Exit exit2 = mockery.mock(Exit.class, "exit2");
    mockery.checking(
        new Expectations() {
          {
            allowing(exit1).visible();
            will(returnValue(true));
            ignoring(exit1);
            allowing(exit2).visible();
            will(returnValue(true));
            ignoring(exit2);
          }
        });
    List<Exit> exits = new ArrayList<Exit>();
    exits.add(exit1);
    exits.add(exit2);

    Location l = createLocation();
    l.addExit(exit1);
    l.addExit(exit2);

    assertEquals(exits, l.visibleExits());
  }
  @Test
  public void should_send_mail_when_parameters_are_correct() {

    final EmailBuilder email = context.mock(EmailBuilder.class);

    context.checking(
        new Expectations() {
          {
            one(email).from("*****@*****.**");
            will(returnValue(email));

            one(email).to("*****@*****.**");
            will(returnValue(email));

            one(email).withSubject("subject");
            will(returnValue(email));

            one(email).withBody("body");
            will(returnValue(email));

            one(email).withCharset("UTF-8");
            will(returnValue(email));

            one(email).send();
          }
        });

    email
        .from("*****@*****.**")
        .to("*****@*****.**")
        .withSubject("subject")
        .withBody("body")
        .withCharset("UTF-8")
        .send();
  }
  @Test
  public void testCompareByName() throws Exception {

    final Category cat1 = context.mock(Category.class, "cat1");
    final Category cat2 = context.mock(Category.class, "cat2");

    context.checking(
        new Expectations() {
          {
            allowing(cat1).getRank();
            will(returnValue(0));
            allowing(cat1).getName();
            will(returnValue("name 2"));
            allowing(cat1).getCategoryId();
            will(returnValue(1L));
            allowing(cat2).getRank();
            will(returnValue(0));
            allowing(cat2).getName();
            will(returnValue("name 1"));
          }
        });

    final SortedSet<Category> set = new TreeSet<Category>(new CategoryRankNameComparator());
    set.addAll(Arrays.asList(cat1, cat2));

    final List<Category> list = new ArrayList<Category>(set);
    assertTrue(cat2 == list.get(0));
    assertTrue(cat1 == list.get(1));
  }
  /** Test. */
  @Test
  public void testWithThemeAndGttIds() {
    final Long themeId = 5L;
    final Long gttId = 6L;
    final MembershipCriteriaDTO mcdto = new MembershipCriteriaDTO();
    mcdto.setCriteria(criteria);
    mcdto.setThemeId(themeId);
    mcdto.setGalleryTabTemplateId(gttId);

    context.checking(
        new Expectations() {
          {
            oneOf(ac).getParams();
            will(returnValue(mcdto));

            oneOf(themeProxyMapper).execute(themeId);
            will(returnValue(theme));

            oneOf(galleryTabTemplateProxyMappery).execute(gttId);
            will(returnValue(gtt));
          }
        });

    PersistenceRequest<MembershipCriteria> result = sut.transform(ac);

    assertEquals(criteria, result.getDomainEnity().getCriteria());
    assertNotNull(result.getDomainEnity().getTheme());
    assertNotNull(result.getDomainEnity().getGalleryTabTemplate());

    context.assertIsSatisfied();
  }
  @Test
  public void testFlattenSelectionJMock2() throws Exception {
    final IAssetType type1 = mockery.mock(IAssetType.class, "type1");
    final IAssetType type2 = mockery.mock(IAssetType.class, "type2");
    final IAttributeDefinition token0 = mockery.mock(IAttributeDefinition.class, "Token0");
    final IAttributeDefinition token1 = mockery.mock(IAttributeDefinition.class, "Token1");

    List<IAttributeDefinition> orig = new LinkedList<IAttributeDefinition>();
    orig.add(token1);
    mockery.checking(
        new Expectations() {
          {
            allowing(token1).getAssetType();
            will(returnValue(type2));
            one(type2).isA(type1);
            will(returnValue(true));
            one(type1).isA(type1);
            will(returnValue(false));
            one(type1).getAttributeDefinition("Token1");
            will(returnValue(token1));

            allowing(token1).getBase();
            will(returnValue(token0));
            one(token1).getName();
            will(returnValue("Token1"));
            one(token0).getAssetType();
            will(returnValue(type1));
          }
        });

    AttributeSelection res = flattenSelection(type1, orig);

    assertEqualsAsSet(null, res, Arrays.asList(token1));
  }
  @Test
  public void available_items_text_includes_only_visible_items() {
    final Item visibleItem = mockery.mock(Item.class, "visible item");
    final Item invisibleItem = mockery.mock(Item.class, "invisible item");
    mockery.checking(
        new Expectations() {
          {
            allowing(visibleItem).visible();
            will(returnValue(true));
            allowing(visibleItem).countableNounPrefix();
            will(returnValue("a"));
            allowing(visibleItem).midSentenceCasedName();
            will(returnValue("visible item"));
            ignoring(visibleItem);
            allowing(invisibleItem).visible();
            will(returnValue(false));
            allowing(invisibleItem).midSentenceCasedName();
            will(returnValue("invisible item"));
            ignoring(invisibleItem);
          }
        });
    Location l = new Location("", "Location description.", null, null);
    l.addItem(visibleItem);
    l.addItem(invisibleItem);

    assertEquals("There is a visible item here.\n", l.availableItemsText());
  }
Пример #29
0
  private ProtocolSubmitAction getMockSubmitAction() {
    final ProtocolSubmitAction action = context.mock(ProtocolSubmitAction.class);

    context.checking(
        new Expectations() {
          {
            allowing(action).getSubmissionTypeCode();
            will(returnValue(ProtocolSubmissionType.INITIAL_SUBMISSION));

            allowing(action).getProtocolReviewTypeCode();
            will(returnValue(ProtocolReviewType.FULL_TYPE_CODE));

            allowing(action).getSubmissionQualifierTypeCode();
            will(returnValue(ProtocolSubmissionQualifierType.ANNUAL_SCHEDULED_BY_IRB));

            allowing(action).getNewCommitteeId();
            will(returnValue(Constants.EMPTY_STRING));

            allowing(action).getNewScheduleId();
            will(returnValue(Constants.EMPTY_STRING));

            allowing(action).getReviewers();
            will(returnValue(new ArrayList<ProtocolReviewerBean>()));
          }
        });

    return action;
  }
  /** Test. Put in 3 things, get a count of 3. */
  @Test
  public void execute() {
    final List<Long> activities = Arrays.asList(1L, 2L, 3L);

    sut = new GetActivityCount(getIdsMock);

    final PrincipalActionContext actionContext = context.mock(PrincipalActionContext.class);
    final String request = "{}";
    final Long userId = 1L;

    final Principal principle = context.mock(Principal.class);

    context.checking(
        new Expectations() {
          {
            oneOf(actionContext).getParams();
            will(returnValue(request));

            oneOf(actionContext).getPrincipal();
            will(returnValue(principle));

            oneOf(principle).getId();
            will(returnValue(userId));

            oneOf(getIdsMock).execute(request, userId);
            will(returnValue(activities));
          }
        });

    Integer result = (Integer) sut.execute(actionContext);
    Assert.assertEquals(new Integer(3), result);

    context.assertIsSatisfied();
  }