示例#1
0
 /** @return */
 public static Address validAddress() {
   final Address address = new Address();
   address.setCity(RandomStringUtils.random(Address.CONSTRAINT_CITY_MAX_SIZE, TestUtils.charSet));
   address.setCountryCode("fr");
   address.setPostalCode(
       RandomStringUtils.random(Address.CONSTRAINT_POSTAL_CODE_MAX_SIZE, TestUtils.charSet));
   address.setStreetAddress(
       RandomStringUtils.random(Address.CONSTRAINT_STREET_ADDRESS_MAX_SIZE, TestUtils.charSet));
   return address;
 }
示例#2
0
 public void addTestingData() {
   em.getTransaction().begin();
   for (int i = 1; i < 10; i++) {
     FacilityEntity entity = new FacilityEntity();
     entity.code = RandomStringUtils.random(10, "abcdefghi987654321");
     entity.desc = RandomStringUtils.random(30, "abcdefghiasdfgbhnjmkl987654321");
     entity.city = "Phoenix";
     entity.state = "Arizona";
     entity.country = "USA";
     em.persist(entity);
   }
   em.getTransaction().commit();
 }
示例#3
0
 public static Advert validAdvert() {
   final Advert advert = new Advert();
   advert.setAddress(TestUtils.validAddress());
   advert.setDescription(
       RandomStringUtils.random(Advert.CONSTRAINT_DESCRIPTION_MAX_SIZE, TestUtils.charSet));
   advert.setEmail("*****@*****.**");
   advert.setName(RandomStringUtils.random(Advert.CONSTRAINT_NAME_MAX_SIZE, TestUtils.charSet));
   advert.setPhoneNumber(
       RandomStringUtils.random(Advert.CONSTRAINT_PHONE_NUMBER_MAX_SIZE, TestUtils.charSet));
   advert.setReference(
       RandomStringUtils.random(Advert.CONSTRAINT_REFERENCE_MAX_SIZE, TestUtils.charSet));
   return advert;
 }
 /** Set up. */
 @Before
 public void setUp() {
   String randomString = RandomStringUtils.random(5);
   SshSessionConfiguration sshConfiguration =
       SshSessionConfigurationFactory.createSshSessionConfigurationWithAuthPhrase(
           helperTestClass.localHost, helperTestClass.port, randomString, randomString);
   clusterService = new TorqueClusterService(sshConfiguration, new HashMap<String, String>());
   clusterService.bindClusterJobSourceService(new ClusterJobSourceServiceImpl());
 }
  @Test
  public void creerAppelNotification() throws UtilisateurInvalideException {
    /** Etant donné un utilsateur à créer. */
    Utilisateur utilisateur = Utilisateur.builder().login(RandomStringUtils.random(10)).build();

    /** Lorsqu'on appelle le service de création. */
    services.creer(utilisateur);

    /** Alors le service de notification est appelé. */
    Mockito.verify(notificationsServices).notifier(Mockito.anyString());
  }
/** @author ggilbert */
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Application.class)
@IfProfileValue(
    name = "include-integration-tests",
    values = {"elasticsearch"})
public class StatementControllerGetCombinationsTest {

  @Autowired
  private ElasticSearchStatementSpringDataRepository elasticSearchStatementSpringDataRepository;

  @Autowired private StatementController statmentController;

  private String statement1Id = RandomStringUtils.random(32);

  @Before
  public void before() {
    // set up data
    XApiActor actor1 = new XApiActor();
    actor1.setMbox("mailto:" + statement1Id + "@test.com");
    XApiVerb verb1 = new XApiVerb();
    verb1.setId("http://example.com/" + statement1Id);
    verb1.setDisplay(Collections.singletonMap("en-US", "verb"));
    XApiObject object1 = new XApiObject();
    object1.setId("http://example.com/" + statement1Id);
    Statement statement1 = new Statement();
    statement1.setId(statement1Id);
    statement1.setActor(actor1);
    statement1.setVerb(verb1);
    statement1.setObject(object1);

    elasticSearchStatementSpringDataRepository.save(statement1);
  }

  @After
  public void after() {
    elasticSearchStatementSpringDataRepository.delete(statement1Id);
  }

  @Test
  public void shouldReturnOneStatementWithGivenId() {
    Statement s = statmentController.getStatement(statement1Id, new HashMap<String, String>());
    Assert.assertNotNull(s);
  }

  @Test
  public void shouldReturnAtLeastOneStatement() {
    StatementResult sr = statmentController.getStatement(null, null, null, null, null);
    Assert.assertNotNull(sr);
    List<Statement> statements = sr.getStatements();
    Assert.assertNotNull(statements);
    Assert.assertTrue(statements.size() > 0);
  }
}
  /** Test. */
  @Test
  public void testEnhanceClusterJobInformation() {
    String jobId0 = RandomStringUtils.random(5);
    String jobId1 = RandomStringUtils.random(5);
    String jobId2 = helperTestClass.localJobId;
    String jobId3 = helperTestClass.remoteJobId;
    String jobId4 = RandomStringUtils.random(5);

    String[] jobIds = new String[] {jobId0, jobId1, jobId2, jobId3};

    Map<String, ClusterJobInformation> jobInformation =
        new HashMap<String, ClusterJobInformation>();
    Map<String, ClusterJobTimesInformation> jobTimesInformation =
        new HashMap<String, ClusterJobTimesInformation>();

    for (String jobId : jobIds) {
      ClusterJobInformationImpl information = new ClusterJobInformationImpl();
      information.setJobId(jobId);
      jobInformation.put(jobId, information);
      if (jobId.equals(jobId1) || jobId.equals(jobId3)) {
        ClusterJobTimesInformation timesInformation = new ClusterJobTimesInformation();
        timesInformation.setJobId(jobId);
        jobTimesInformation.put(jobId, timesInformation);
      }
    }

    String queueTime1 = RandomStringUtils.random(5);
    jobTimesInformation.get(jobId1).setQueueTime(queueTime1);

    String remainingTime3 = RandomStringUtils.random(5);
    String startTime3 = RandomStringUtils.random(5);
    jobTimesInformation.get(jobId3).setRemainingTime(remainingTime3);
    jobTimesInformation.get(jobId3).setStartTime(startTime3);

    Set<ClusterJobInformation> resultJobInformation =
        clusterService.enhanceClusterJobInformation(jobInformation, jobTimesInformation);

    assertEquals(jobInformation.size(), resultJobInformation.size());
    for (ClusterJobInformation information : resultJobInformation) {
      if (information.getJobId().equals(jobId0)) {
        assertEquals(ClusterJobInformationImpl.NO_VALUE_SET, information.getQueueTime());
        assertEquals(ClusterJobInformationImpl.NO_VALUE_SET, information.getRemainingTime());
        assertEquals(ClusterJobInformationImpl.NO_VALUE_SET, information.getStartTime());
      } else if (information.getJobId().equals(jobId1)) {
        assertEquals(queueTime1, information.getQueueTime());
        assertEquals(ClusterJobInformationImpl.NO_VALUE_SET, information.getRemainingTime());
        assertEquals(ClusterJobInformationImpl.NO_VALUE_SET, information.getStartTime());
      } else if (information.getJobId().equals(jobId2)) {
        assertEquals(ClusterJobInformationImpl.NO_VALUE_SET, information.getQueueTime());
        assertEquals(ClusterJobInformationImpl.NO_VALUE_SET, information.getRemainingTime());
        assertEquals(ClusterJobInformationImpl.NO_VALUE_SET, information.getStartTime());
      } else if (information.getJobId().equals(jobId3)) {
        assertEquals(ClusterJobInformationImpl.NO_VALUE_SET, information.getQueueTime());
        assertEquals(remainingTime3, information.getRemainingTime());
        assertEquals(startTime3, information.getStartTime());
      }
    }
    assertFalse(resultJobInformation.contains(jobId4));
  }
  @Test
  public void creerVerificationExistanceUtilisateur() throws UtilisateurInvalideException {
    /** Etant donné un utilsateur à créer. */
    Utilisateur utilisateur = Utilisateur.builder().login(RandomStringUtils.random(10)).build();
    /* Et que l'utilisateur existe sur le système */
    UtilisateursServices spy = Mockito.spy(services);
    Mockito.when(spy.rechercherParLogin(utilisateur.getLogin())).thenReturn(utilisateur);

    try {
      /** Lorsqu'on appelle le service de création. */
      spy.creer(utilisateur);

      fail("Une exception devrait être levée.");
    } catch (UtilisateurInvalideException e) {
      /** Alors le service de vérification de l'existance de l'utilsiateur est appelé. */
      Mockito.verify(spy).rechercherParLogin(utilisateur.getLogin());

      /* Et une exception est levée. */
      Assert.assertEquals(
          UtilisateurInvalideException.ErreurUtilisateur.UTILISATEUR_EXISTANT, e.getErreur());
    }
  }
示例#9
0
 public static String randomStringWithCommonLang3(int len) {
   return RandomStringUtils.random(len, baseChars);
 }
示例#10
0
 /**
  * Generates a random secure token of length {@link #TOKEN_LENGTH} characters with alphanumeric
  * characters {@code A-Z_a-z_0-9}.
  *
  * @return a new generated random alphanumeric string.
  */
 public String generateToken() {
   return RandomStringUtils.random(
       TOKEN_LENGTH, 0, 0, LETTERS_GENERATION, NUMBER_GENERATION, null, SECURE_RANDOM);
 }
示例#11
0
 /**
  * Generate a random fake SHA hex string.
  *
  * @return Fake SHA string.
  */
 private static String fakeSha() {
   // @checkstyle MagicNumberCheck (1 line)
   return RandomStringUtils.random(40, "0123456789abcdef");
 }
示例#12
0
 public String generateRoomId() {
   return format("!%s:%s", RandomStringUtils.random(18, true, false), DOMAIN);
 }