@BeforeClass
  public static void init() throws Exception {
    applicationContext = mock(ApplicationContext.class);
    dataAccessService = mock(DataAccessService.class);
    translationService = mock(TranslationService.class);

    dataDefinitionService = new DataDefinitionServiceImpl();

    modelXmlToDefinitionConverter = new ModelXmlToDefinitionConverterImpl();
    setField(modelXmlToDefinitionConverter, "dataDefinitionService", dataDefinitionService);
    setField(modelXmlToDefinitionConverter, "dataAccessService", dataAccessService);
    setField(modelXmlToDefinitionConverter, "applicationContext", applicationContext);
    setField(modelXmlToDefinitionConverter, "translationService", translationService);

    given(applicationContext.getBean(CustomHook.class)).willReturn(new CustomHook());

    modelXmlToClassConverter = new ModelXmlToClassConverterImpl();
    ((ModelXmlToClassConverterImpl) modelXmlToClassConverter)
        .setBeanClassLoader(ClassLoader.getSystemClassLoader());

    dataDefinitions =
        performConvert(
            Utils.FULL_FIRST_ENTITY_XML_RESOURCE,
            Utils.FULL_SECOND_ENTITY_XML_RESOURCE,
            Utils.FULL_THIRD_ENTITY_XML_RESOURCE,
            Utils.OTHER_FIRST_ENTITY_XML_RESOURCE,
            Utils.OTHER_SECOND_ENTITY_XML_RESOURCE);

    for (DataDefinition dd : dataDefinitions.toArray(new DataDefinition[dataDefinitions.size()])) {
      if (dd.getName().equals("firstEntity") && dd.getPluginIdentifier().equals("full")) {
        dataDefinition = (InternalDataDefinition) dd;
      }
    }
  }
 @Before
 public void setup() {
   UserResource userResource = new UserResource();
   ReflectionTestUtils.setField(userResource, "userRepository", userRepository);
   ReflectionTestUtils.setField(userResource, "userService", userService);
   this.restUserMockMvc = MockMvcBuilders.standaloneSetup(userResource).build();
 }
예제 #3
0
  @Test
  public void shouldPrepareViewForParameters() throws Exception {
    // // given
    Map<String, String> arguments = ImmutableMap.of("context", "{\"form.id\":\"13\"}");
    ModelAndView expectedMav = mock(ModelAndView.class);
    CrudService crudController = mock(CrudService.class);
    given(
            crudController.prepareView(
                BasicConstants.PLUGIN_IDENTIFIER,
                BasicConstants.VIEW_PARAMETERS,
                arguments,
                Locale.ENGLISH))
        .willReturn(expectedMav);

    ParameterService parameterService = mock(ParameterService.class);
    given(parameterService.getParameterId()).willReturn(13L);

    BasicController basicController = new BasicController();
    setField(basicController, "crudController", crudController);
    setField(basicController, "parameterService", parameterService);

    // // when
    ModelAndView mav = basicController.getParameterPageView(Locale.ENGLISH);

    // // then
    assertEquals(expectedMav, mav);
  }
예제 #4
0
 @Before
 public void setUp() {
   initMocks(this);
   formValidator = new FormValidator();
   ReflectionTestUtils.setField(formValidator, "facilityService", facilityService);
   ReflectionTestUtils.setField(formValidator, "staffService", staffService);
 }
 @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));
 }
예제 #6
0
  @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 before() {
    securityFilter = new SecurityFilter();
    ReflectionTestUtils.setField(securityFilter, "loggedInUser", loggedInUser);
    ReflectionTestUtils.setField(securityFilter, "userFacade", userFacade);

    SecurityContextHolder.getContext().setAuthentication(mockAuthentication);
  }
예제 #8
0
 @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();
 }
예제 #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 setUp() {
    initMocks(this);

    repoRestore = new FedoraRepositoryRestore();
    setField(repoRestore, "session", mockSession);
    setField(repoRestore, "repositoryService", mockService);
    setField(repoRestore, "uriInfo", getUriInfoImpl());
  }
예제 #11
0
  @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");
  }
 @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() {
   MockitoAnnotations.initMocks(this);
   ReflectionTestUtils.setField(callbackService, "restTemplate", restTemplateMock);
   ReflectionTestUtils.setField(userManagerService, "restTemplate", restTemplateMock);
   repository.deleteAll();
   callbackUrl = "http://localhost:" + port + "/onracestatusupdate";
   RestAssured.port = port;
 }
예제 #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();
 }
 @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();
 }
 @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();
 }
 @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>();
 }
  @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();
    }
  }
 @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();
 }
예제 #23
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);
  }
 @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();
 }
  @Before
  public void setUp() throws RepositoryException {

    roleProvider = new WebACRolesProvider();
    setField(roleProvider, "nodeService", mockNodeService);
    setField(roleProvider, "sessionFactory", mockSessionFactory);

    when(mockNodeService.cast(mockNode)).thenReturn(mockResource);
    when(mockNode.getSession()).thenReturn(mockSession);
    when(mockSessionFactory.getInternalSession()).thenReturn(mockSession);

    when(mockResource.getNode()).thenReturn(mockNode);
    when(mockNode.getDepth()).thenReturn(0);
  }
  @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();
  }
예제 #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);
 }
예제 #28
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());
  }
  @Test
  public void getOrchestratorWhenExist() throws CloudbreakException {
    ReflectionTestUtils.setField(underTest, "containerOrchestratorName", "test1");
    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);

    ContainerOrchestrator containerOrchestrator = underTest.get();
    assertNotNull(containerOrchestrator);
  }