@Before
  public final void init() {
    workPlanService = new WorkPlansServiceImpl();

    dataDefinitionService = mock(DataDefinitionService.class);
    TranslationService translationService = mock(TranslationService.class);
    workPlan = mock(Entity.class);
    workPlanDD = mock(DataDefinition.class);

    when(dataDefinitionService.get(
            WorkPlansConstants.PLUGIN_IDENTIFIER, WorkPlansConstants.MODEL_WORK_PLAN))
        .thenReturn(workPlanDD);

    when(translationService.translate(
            Mockito.anyString(), Mockito.any(Locale.class), Mockito.anyString()))
        .thenReturn(TRANSLATED_STRING);

    when(workPlanDD.getName()).thenReturn(WorkPlansConstants.MODEL_WORK_PLAN);
    when(workPlanDD.getPluginIdentifier()).thenReturn(WorkPlansConstants.PLUGIN_IDENTIFIER);
    when(workPlanDD.get(Mockito.anyLong())).thenReturn(workPlan);

    when(workPlan.getDataDefinition()).thenReturn(workPlanDD);
    when(workPlan.getId()).thenReturn(1L);

    ReflectionTestUtils.setField(workPlanService, "dataDefinitionService", dataDefinitionService);
    ReflectionTestUtils.setField(workPlanService, "translationService", translationService);
  }
 @Before
 public void setup() {
   UserResource userResource = new UserResource();
   ReflectionTestUtils.setField(userResource, "userRepository", userRepository);
   ReflectionTestUtils.setField(userResource, "userService", userService);
   this.restUserMockMvc = MockMvcBuilders.standaloneSetup(userResource).build();
 }
 @Before
 public void setUp() {
   initMocks(this);
   formValidator = new FormValidator();
   ReflectionTestUtils.setField(formValidator, "facilityService", facilityService);
   ReflectionTestUtils.setField(formValidator, "staffService", staffService);
 }
  @Test
  public void parseInternal_withMinimalConfig_shouldCreateDefaultTemplate() throws Exception {
    // Arrange
    DefaultListableBeanFactory registry = new DefaultListableBeanFactory();
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(registry);

    // Act
    reader.loadBeanDefinitions(
        new ClassPathResource(getClass().getSimpleName() + "-minimal.xml", getClass()));

    // Assert
    NotificationMessagingTemplate notificationMessagingTemplate =
        registry.getBean(NotificationMessagingTemplate.class);
    assertSame(
        registry.getBean(AmazonSNSClient.class),
        ReflectionTestUtils.getField(notificationMessagingTemplate, "amazonSns"));

    Object cachingDestinationResolverProxy =
        ReflectionTestUtils.getField(notificationMessagingTemplate, "destinationResolver");
    Object targetDestinationResolver =
        ReflectionTestUtils.getField(cachingDestinationResolverProxy, "targetDestinationResolver");
    assertEquals(
        registry.getBean(GlobalBeanDefinitionUtils.RESOURCE_ID_RESOLVER_BEAN_NAME),
        ReflectionTestUtils.getField(targetDestinationResolver, "resourceIdResolver"));

    assertTrue(
        StringMessageConverter.class.isInstance(
            notificationMessagingTemplate.getMessageConverter()));
    assertEquals(
        String.class,
        ReflectionTestUtils.getField(
            notificationMessagingTemplate.getMessageConverter(), "serializedPayloadClass"));
  }
 @Test
 public void testParseWithDefaults() throws Exception {
   SimpleMessageListenerContainer container =
       beanFactory.getBean("container4", SimpleMessageListenerContainer.class);
   assertEquals(1, ReflectionTestUtils.getField(container, "concurrentConsumers"));
   assertEquals(true, ReflectionTestUtils.getField(container, "defaultRequeueRejected"));
 }
 @Before
 public void setUp() throws Exception {
   MockitoAnnotations.initMocks(this);
   ReflectionTestUtils.setField(createAccountCmd, "domainId", domainId);
   ReflectionTestUtils.setField(createAccountCmd, "accountType", accountType);
   CallContext.register(Mockito.mock(User.class), Mockito.mock(Account.class));
 }
 @PostConstruct
 public void setup() {
   MockitoAnnotations.initMocks(this);
   ForumResource forumResource = new ForumResource();
   ReflectionTestUtils.setField(forumResource, "forumRepository", forumRepository);
   ReflectionTestUtils.setField(forumResource, "forumSearchRepository", forumSearchRepository);
   this.restForumMockMvc = MockMvcBuilders.standaloneSetup(forumResource).build();
 }
 @Test
 public void testParseWithDefaultQueueRejectedFalse() throws Exception {
   SimpleMessageListenerContainer container =
       beanFactory.getBean("container5", SimpleMessageListenerContainer.class);
   assertEquals(1, ReflectionTestUtils.getField(container, "concurrentConsumers"));
   assertEquals(false, ReflectionTestUtils.getField(container, "defaultRequeueRejected"));
   assertFalse(container.isChannelTransacted());
 }
示例#9
0
 @Before
 public void init() {
   MockitoAnnotations.initMocks(this);
   tc = new MobileController();
   ReflectionTestUtils.setField(tc, "tripsService", tripsService);
   ReflectionTestUtils.setField(tc, "messageSource", messageSource);
   mockMvc = MockMvcBuilders.standaloneSetup(tc).build();
 }
  @Before
  public void before() {
    securityFilter = new SecurityFilter();
    ReflectionTestUtils.setField(securityFilter, "loggedInUser", loggedInUser);
    ReflectionTestUtils.setField(securityFilter, "userFacade", userFacade);

    SecurityContextHolder.getContext().setAuthentication(mockAuthentication);
  }
 @Before
 public void setup() {
   MockitoAnnotations.initMocks(this);
   ReflectionTestUtils.setField(callbackService, "restTemplate", restTemplateMock);
   ReflectionTestUtils.setField(userManagerService, "restTemplate", restTemplateMock);
   repository.deleteAll();
   callbackUrl = "http://localhost:" + port + "/onracestatusupdate";
   RestAssured.port = port;
 }
 @Before
 public void before() {
   jobStatisticService = new VietnamWorksJobStatisticService();
   ReflectionTestUtils.setField(
       jobStatisticService, "elasticsearchTemplate", elasticsearchTemplate);
   ReflectionTestUtils.setField(jobStatisticService, "jobQueryBuilder", jobQueryBuilder);
   ReflectionTestUtils.setField(
       jobStatisticService, "elasticSearchIndexName", elasticSearchIndexName);
 }
  @Before
  public void setup() throws Exception {
    testDateTimeProvider.setTime(LocalDateTime.parse("2001-02-04T17:00:00"));
    databaseHelper.addObjects(OWNER_MNT, TEST_PERSON);

    ReflectionTestUtils.setField(
        restClient, "restApiUrl", String.format("http://localhost:%d/whois", getPort()));
    ReflectionTestUtils.setField(restClient, "sourceName", "TEST");
  }
示例#14
0
  @Test
  public void canUserEditApplicationTest() {
    // Initial setup
    User user = getUser();
    userService.add(user);
    Organization organization = createOrganization();
    Category category = createCategory(organization);
    organization.getCategories().add(category);
    Application application =
        createApplication(category, "Test Application", AppState.GROUP_PUBLISH);
    Group group = createGroup(organization);
    group.getOwnedApplications().add(application);

    entityManager.flush();

    createUserDomain(user, group.getId(), DomainType.GROUP, UserRole.ROLE_GROUP_ADMIN);
    entityManager.flush();

    assertTrue(userService.canUserEditApplication(user.getId(), application.getId()));

    // Reset
    userService.delete(user.getId());
    ReflectionTestUtils.setField(this, "user", null);
    entityManager.flush();

    // Test if org admin can edit application
    user = getUser();
    userService.add(user);
    entityManager.flush();
    createUserDomain(user, organization.getId(), DomainType.ORGANIZATION, UserRole.ROLE_ORG_ADMIN);
    entityManager.flush();
    assertTrue(userService.canUserEditApplication(user.getId(), application.getId()));

    // Reset
    userService.delete(user.getId());
    ReflectionTestUtils.setField(this, "user", null);
    entityManager.flush();

    // Test user is org user
    user = getUser();
    userService.add(user);
    entityManager.flush();
    createUserDomain(user, organization.getId(), DomainType.ORGANIZATION, UserRole.ROLE_ORG_USER);
    entityManager.flush();
    assertFalse(userService.canUserEditApplication(user.getId(), application.getId()));

    // Reset
    userService.delete(user.getId());
    ReflectionTestUtils.setField(this, "user", null);
    entityManager.flush();

    // Test user is not part of organization and not group admin
    user = getUser();
    userService.add(user);
    entityManager.flush();
    assertFalse(userService.canUserEditApplication(user.getId(), application.getId()));
  }
 @Test
 public void beginRender() {
   Block block = mock(Block.class);
   ReflectionTestUtils.setField(victim, "elseBlock", block);
   ReflectionTestUtils.setField(victim, "ifAnyGranted", PERMISSION);
   SecurityContextHolder.getContext()
       .setAuthentication(new TestingAuthenticationToken(USER, null, PERMISSION));
   victim.setupRender();
   assertNull(victim.beginRender());
 }
示例#16
0
  @Before
  public void setup() {

    TagController tagController = new TagController();
    ReflectionTestUtils.setField(tagController, "timelineService", timelineService);
    ReflectionTestUtils.setField(tagController, "tagMembershipService", tagMembershipService);
    ReflectionTestUtils.setField(tagController, "userTagRepository", userTagRepository);

    User authenticateUser = constructAUser(username + "@ippon.fr");
    AuthenticationService mockAuthenticationService = mock(AuthenticationService.class);
    when(mockAuthenticationService.getCurrentUser()).thenReturn(authenticateUser);
    ReflectionTestUtils.setField(tagController, "authenticationService", mockAuthenticationService);
    ReflectionTestUtils.setField(
        timelineService, "authenticationService", mockAuthenticationService);
    ReflectionTestUtils.setField(
        statusUpdateService, "authenticationService", mockAuthenticationService);
    ReflectionTestUtils.setField(
        tagMembershipService, "authenticationService", mockAuthenticationService);
    this.mockMvc = MockMvcBuilders.standaloneSetup(tagController).build();

    TimelineController timelineController = new TimelineController();
    ReflectionTestUtils.setField(timelineController, "timelineService", timelineService);
    ReflectionTestUtils.setField(timelineController, "statusUpdateService", statusUpdateService);
    this.timelineMockMvc = MockMvcBuilders.standaloneSetup(timelineController).build();
  }
 @PostConstruct
 public void setup() {
   MockitoAnnotations.initMocks(this);
   PictureResource pictureResource = new PictureResource();
   ReflectionTestUtils.setField(pictureResource, "pictureRepository", pictureRepository);
   ReflectionTestUtils.setField(pictureResource, "pictureMapper", pictureMapper);
   this.restPictureMockMvc =
       MockMvcBuilders.standaloneSetup(pictureResource)
           .setMessageConverters(jacksonMessageConverter)
           .build();
 }
 @Before
 public void setup() {
   initMocks(this);
   someUrl = "http://localhost:8000";
   spyCommcareGateway = spy(new CommcareGateway(null));
   ReflectionTestUtils.setField(spyCommcareGateway, "httpClientService", mockHttpClientService);
   ReflectionTestUtils.setField(spyCommcareGateway, "velocityEngine", mockVelocityEngine);
   ReflectionTestUtils.setField(spyCommcareGateway, "allGroups", mockAllGroups);
   ReflectionTestUtils.setField(spyCommcareGateway, "allUsers", allUsers);
   ReflectionTestUtils.setField(spyCommcareGateway, "COMMCARE_RECIEVER_URL", someUrl);
   model = new HashMap<String, Object>();
 }
  @Test
  public void testSetTypeConvertersInOrder() throws Exception {
    List org = (List) ReflectionTestUtils.getField(converterHelper, "typeConvertersInOrder");
    TypeConverter typeConverter = mock(TypeConverter.class);
    assertThat(org.size()).isEqualTo(0); // default is empty

    converterHelper.setTypeConvertersInOrder(Collections.singletonList(typeConverter));
    List res = (List) ReflectionTestUtils.getField(converterHelper, "typeConvertersInOrder");
    assertThat(res.size()).isEqualTo(1);
    assertThat((Object) res).isInstanceOf(LockableList.class);
    assertThat((Boolean) ReflectionTestUtils.getField(res, "readOnly")).isTrue();
  }
 @PostConstruct
 public void setup() {
   MockitoAnnotations.initMocks(this);
   DepartmentResource departmentResource = new DepartmentResource();
   ReflectionTestUtils.setField(departmentResource, "departmentService", departmentService);
   ReflectionTestUtils.setField(departmentResource, "departmentMapper", departmentMapper);
   this.restDepartmentMockMvc =
       MockMvcBuilders.standaloneSetup(departmentResource)
           .setCustomArgumentResolvers(pageableArgumentResolver)
           .setMessageConverters(jacksonMessageConverter)
           .build();
 }
 @PostConstruct
 public void setup() {
   MockitoAnnotations.initMocks(this);
   CycleResource cycleResource = new CycleResource();
   ReflectionTestUtils.setField(cycleResource, "cycleSearchRepository", cycleSearchRepository);
   ReflectionTestUtils.setField(cycleResource, "cycleRepository", cycleRepository);
   this.restCycleMockMvc =
       MockMvcBuilders.standaloneSetup(cycleResource)
           .setCustomArgumentResolvers(pageableArgumentResolver)
           .setMessageConverters(jacksonMessageConverter)
           .build();
 }
  @Before
  public void prepare() {
    MongoDBInstance.start();
    try {
      MongoProvider provider = new MongoProvider("localhost", 10000, "test", null, null);
      orgDao = new OrganizationDao();
      ReflectionTestUtils.setField(orgDao, "provider", provider);

      org = new Organization();
      org.setOrganizationId("orgId");
      org.setDatasets(new ArrayList<Dataset>());
      org.setOrganizationUri("testUri");
      org.setHarvestingMetadata(new HarvestingMetadata());
      ds = new Dataset();
      ds.setAccepted(true);
      ds.setAssignedToLdapId("Lemmy");
      ds.setCountry(Country.ALBANIA);
      ds.setCreated(new Date(1000));
      ds.setCreatedByLdapId("Lemmy");
      ds.setDataProvider("prov");
      ds.setDeaSigned(true);
      ds.setDescription("Test description");
      List<String> DQA = new ArrayList<>();
      DQA.add("test DQA");
      ds.setDQA(DQA);
      ds.setFirstPublished(new Date(1000));
      ds.setHarvestedAt(new Date(1000));
      ds.setLanguage(Language.AR);
      ds.setLastPublished(new Date(1000));
      ds.setMetadata(new OAIDatasetMetadata());
      ds.setName("testName");
      ds.setNotes("test Notes");
      ds.setRecordsPublished(100);
      ds.setRecordsSubmitted(199);
      ds.setReplacedBy("replacedBY");
      List<String> sources = new ArrayList<>();
      sources.add("testSource");
      ds.setSource(sources);
      List<String> subjects = new ArrayList<>();
      subjects.add("testSubject");
      ds.setSubject(subjects);
      ds.setSubmittedAt(new Date(1000));
      ds.setUpdated(new Date(1000));
      ds.setWorkflowStatus(WorkflowStatus.ACCEPTANCE);

      dsDao = new DatasetDao();
      ReflectionTestUtils.setField(dsDao, "provider", provider);

    } catch (IOException e) {
      e.printStackTrace();
    }
  }
  /**
   * @see <a href="https://jira.spring.io/browse/DATACASS-226">DATACASS-226</a>
   * @see <a href="https://jira.spring.io/browse/DATACASS-263">DATACASS-263</a>
   * @throws Exception
   */
  @Test
  public void shouldSetAuthentication() throws Exception {

    CassandraCqlClusterFactoryBean bean = new CassandraCqlClusterFactoryBean();
    bean.setUsername("user");
    bean.setPassword("password");
    bean.afterPropertiesSet();

    AuthProvider result = getConfiguration(bean).getProtocolOptions().getAuthProvider();
    assertThat(result).isNotNull();
    assertThat(ReflectionTestUtils.getField(result, "username")).isEqualTo((Object) "user");
    assertThat(ReflectionTestUtils.getField(result, "password")).isEqualTo((Object) "password");
  }
示例#24
0
  @Before
  public void setUp() {
    service = new RedisContactService();

    contactIdCounterMock = mock(RedisAtomicLong.class);
    ReflectionTestUtils.setField(service, "contactIdCounter", contactIdCounterMock);

    redisTemplateMock = mock(RedisTemplate.class);
    ReflectionTestUtils.setField(service, "redisTemplate", redisTemplateMock);

    boundHashOperationsMock = mock(BoundHashOperations.class);
    setOperationsMock = mock(SetOperations.class);
  }
 @PostConstruct
 public void setup() {
   MockitoAnnotations.initMocks(this);
   FuncionarioResource funcionarioResource = new FuncionarioResource();
   ReflectionTestUtils.setField(
       funcionarioResource, "funcionarioRepository", funcionarioRepository);
   ReflectionTestUtils.setField(funcionarioResource, "funcionarioService", funcionarioService);
   this.restFuncionarioMockMvc =
       MockMvcBuilders.standaloneSetup(funcionarioResource)
           .setCustomArgumentResolvers(pageableArgumentResolver)
           .setMessageConverters(jacksonMessageConverter)
           .build();
 }
 @Test
 public void testOnNodeRemoved() {
   OperationsNodeInfo nodeInfo = Mockito.mock(OperationsNodeInfo.class);
   ConnectionInfo connectionInfo = Mockito.mock(ConnectionInfo.class);
   Mockito.when(nodeInfo.getConnectionInfo()).thenReturn(connectionInfo);
   Map<String, OperationsNodeInfo> opsMap = Mockito.mock(Map.class);
   ReflectionTestUtils.setField(service, "opsMap", opsMap);
   DefaultOperationsServerListService.Memorizer memorizer =
       Mockito.mock(DefaultOperationsServerListService.Memorizer.class);
   ReflectionTestUtils.setField(service, "cache", memorizer);
   service.onNodeRemoved(nodeInfo);
   Mockito.verify(opsMap, Mockito.only()).remove(Mockito.anyString());
   Mockito.verify(memorizer, Mockito.only()).clear();
 }
示例#27
0
 @Before
 public void initBeforeTest() throws Exception {
   initMocks(this);
   service = new IntermediaireService();
   ReflectionTestUtils.setField(
       service,
       "paramsPortefeuilleService",
       paramsPortefeuilleServiceMock,
       IParamsPortefeuilleService.class);
   ReflectionTestUtils.setField(
       service, "genericService", genericServiceMock, IGenericService.class);
   ReflectionTestUtils.setField(
       service, "vitrineService", vitrineServiceMock, IGestionIdentiteAgenceServiceProxy.class);
 }
  @Test(expected = CloudbreakException.class)
  public void getOrchestratorWhenNotExist() throws CloudbreakException {
    ReflectionTestUtils.setField(underTest, "containerOrchestratorName", "test3");
    Map<String, ContainerOrchestrator> map = new HashMap<>();
    TestOneMockContainerOrchestrator testOneMockContainerOrchestrator =
        new TestOneMockContainerOrchestrator();
    map.put(testOneMockContainerOrchestrator.name(), testOneMockContainerOrchestrator);
    TestTwoMockContainerOrchestrator testTwoMockContainerOrchestrator =
        new TestTwoMockContainerOrchestrator();
    map.put(testTwoMockContainerOrchestrator.name(), testTwoMockContainerOrchestrator);
    ReflectionTestUtils.setField(underTest, "containerOrchestrators", map);

    underTest.get();
  }
示例#29
0
  @Before
  public void init() {
    orderHooksCNFM = new OrderHooksCNFM();

    MockitoAnnotations.initMocks(this);

    ReflectionTestUtils.setField(
        orderHooksCNFM, "costNormsForMaterialsService", costNormsForMaterialsService);
    ReflectionTestUtils.setField(orderHooksCNFM, "dataDefinitionService", dataDefinitionService);

    when(order.getDataDefinition()).thenReturn(orderDD);
    when(dataDefinitionService.get("costNormsForMaterials", "technologyInstOperProductInComp"))
        .thenReturn(techInsOperCompProdInDD);
  }
  @Before
  public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);

    ReflectionTestUtils.setField(
        this.recentlyUpdatedService, "applicationProperties", applicationProperties);
    ReflectionTestUtils.setField(
        this.recentlyUpdatedService, "entityReferenceHelper", this.entityReferenceHelper);
    ReflectionTestUtils.setField(
        this.recentlyUpdatedService, "repository", this.recentUpdateRepository);
    ReflectionTestUtils.setField(this.recentlyUpdatedService, "messageSource", this.messageSource);

    Mockito.when(this.recentlyUpdatedService.getRecentUpdateListener())
        .thenReturn(acceptNoneListener());
  }