@Test
 public void shouldGetCorrectListOfMonths() {
   DateUtils dateUtils = new DateUtils();
   final String[] months = dateUtils.getShortFormMonthsOfYear();
   final String[] keys =
       new String[] {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"};
   Map<String, String> actualMonths = underTest.populateMonths();
   assertEquals("expect size to be 12", 12, actualMonths.size());
   assertArrayEquals(months, actualMonths.values().toArray());
   assertArrayEquals(keys, actualMonths.keySet().toArray());
 }
  @Test
  public void setTemplateShouldCopyParametersAndLabels() {
    Map<String, IParameter> parameters = givenTheTemplateHasParameters();
    HashMap<String, String> labels = givenTheTemplateHasObjectLabels();
    Collection<IResourceLabelsPageModel.Label> modelLabels =
        new ArrayList<IResourceLabelsPageModel.Label>();
    for (Entry<String, String> label : labels.entrySet()) {
      modelLabels.add(new IResourceLabelsPageModel.Label(label.getKey(), label.getValue()));
    }
    model.setUseLocalTemplate(false);
    model.setServerTemplate(template);

    assertArrayEquals(parameters.values().toArray(), model.getParameters().toArray());
    assertArrayEquals(modelLabels.toArray(), model.getLabels().toArray());
  }
  @Test
  public void testGetSystemRoles() throws Exception {
    IUserRoleListService mockService = mock(IUserRoleListService.class);
    when(mockService.getSystemRoles()).thenReturn(Arrays.asList("foo", "bar"));

    CachingUserRoleListServiceDecorator decorator =
        new CachingUserRoleListServiceDecorator(mockService);
    List<String> allRoles = decorator.getSystemRoles();
    assertArrayEquals("does not match", new String[] {"foo", "bar"}, allRoles.toArray());

    // second call should be from cache
    allRoles = decorator.getSystemRoles();
    assertArrayEquals("does not match", new String[] {"foo", "bar"}, allRoles.toArray());

    verify(mockService, times(1)).getSystemRoles();
  }
 @Test
 public void getExplorerElementsForRegistryReturnsConnections() {
   assertArrayEquals(
       "Exp. to get all the connections from the ConnectionsRegistry",
       new Object[] {connection},
       provider.getExplorerElements(registry));
 }
  @Test
  public void handleMessageFromClient() {

    TextMessage textMessage =
        StompTextMessageBuilder.create(StompCommand.CONNECT)
            .headers(
                "login:guest", "passcode:guest", "accept-version:1.1,1.0", "heart-beat:10000,10000")
            .build();

    this.protocolHandler.handleMessageFromClient(this.session, textMessage, this.channel);

    verify(this.channel).send(this.messageCaptor.capture());
    Message<?> actual = this.messageCaptor.getValue();
    assertNotNull(actual);

    StompHeaderAccessor headers = StompHeaderAccessor.wrap(actual);
    assertEquals(StompCommand.CONNECT, headers.getCommand());
    assertEquals("s1", headers.getSessionId());
    assertEquals("joe", headers.getUser().getName());
    assertEquals("guest", headers.getLogin());
    assertEquals("PROTECTED", headers.getPasscode());
    assertArrayEquals(new long[] {10000, 10000}, headers.getHeartbeat());
    assertEquals(new HashSet<>(Arrays.asList("1.1", "1.0")), headers.getAcceptVersion());

    assertEquals(0, this.session.getSentMessages().size());
  }
  @Test
  public void handleMessageToClientConnectAck() {

    StompHeaderAccessor connectHeaders = StompHeaderAccessor.create(StompCommand.CONNECT);
    connectHeaders.setHeartbeat(10000, 10000);
    connectHeaders.setNativeHeader(StompHeaderAccessor.STOMP_ACCEPT_VERSION_HEADER, "1.0,1.1");
    Message<?> connectMessage =
        MessageBuilder.withPayload(new byte[0]).setHeaders(connectHeaders).build();

    SimpMessageHeaderAccessor connectAckHeaders =
        SimpMessageHeaderAccessor.create(SimpMessageType.CONNECT_ACK);
    connectAckHeaders.setHeader(SimpMessageHeaderAccessor.CONNECT_MESSAGE_HEADER, connectMessage);
    Message<byte[]> connectAckMessage =
        MessageBuilder.withPayload(new byte[0]).setHeaders(connectAckHeaders).build();

    this.protocolHandler.handleMessageToClient(this.session, connectAckMessage);

    verifyNoMoreInteractions(this.channel);

    // Check CONNECTED reply

    assertEquals(1, this.session.getSentMessages().size());
    TextMessage textMessage = (TextMessage) this.session.getSentMessages().get(0);
    Message<?> message =
        new StompDecoder().decode(ByteBuffer.wrap(textMessage.getPayload().getBytes()));
    StompHeaderAccessor replyHeaders = StompHeaderAccessor.wrap(message);

    assertEquals(StompCommand.CONNECTED, replyHeaders.getCommand());
    assertEquals("1.1", replyHeaders.getVersion());
    assertArrayEquals(new long[] {0, 0}, replyHeaders.getHeartbeat());
    assertEquals("joe", replyHeaders.getNativeHeader("user-name").get(0));
  }
  @Test
  public void getParametersShouldReturnAParameterMapWhenTemplateIsNotNull() {
    Map<String, IParameter> parameters = givenTheTemplateHasParameters();
    model.setUseLocalTemplate(false);
    model.setServerTemplate(template);

    assertArrayEquals(parameters.values().toArray(), model.getParameters().toArray());
  }
 /** Test method for {@link CriterionParser#CriterionParser(DatabaseSession, String)}. */
 @Test
 public void testCriterionParserDatabaseSessionString() {
   assertEquals(mockSession, testParser.getSession());
   String[] criterionFields = (String[]) getField(testParser, "fields");
   assertArrayEquals(criterionFields, CRITERION_STRING.split(";"));
   MetricDao dao = (MetricDao) getField(testParser, METRIC_DAO_FIELD);
   assertEquals(mockSession, dao.getSession());
 }
  @Test
  public void testSetDbPath() throws Exception {
    RocksDBStateBackend rocksDbBackend = new RocksDBStateBackend(TEMP_URI);

    assertNull(rocksDbBackend.getDbStoragePaths());

    rocksDbBackend.setDbStoragePath("/abc/def");
    assertArrayEquals(new String[] {"/abc/def"}, rocksDbBackend.getDbStoragePaths());

    rocksDbBackend.setDbStoragePath(null);
    assertNull(rocksDbBackend.getDbStoragePaths());

    rocksDbBackend.setDbStoragePaths("/abc/def", "/uvw/xyz");
    assertArrayEquals(new String[] {"/abc/def", "/uvw/xyz"}, rocksDbBackend.getDbStoragePaths());

    //noinspection NullArgumentToVariableArgMethod
    rocksDbBackend.setDbStoragePaths(null);
    assertNull(rocksDbBackend.getDbStoragePaths());
  }
  @Test
  public void getChildrenForConnectionReturnsProjects() {
    List<IProject> projects = Arrays.asList(new IProject[] {project});
    when(client.<IProject>list(ResourceKind.PROJECT)).thenReturn(projects);

    assertArrayEquals(
        "Exp. to get all the projects for a Connection",
        projects.toArray(),
        provider.getChildrenFor(connection));
  }
  @Test
  public void askMoveDestination() {
    when(roleManager.getCanMoveTopics()).thenReturn(true);
    when(categoryRepository.getAllCategories()).thenReturn(new ArrayList<Category>());

    controller.askMoveDestination("return path", 10, 1, 2, 3);

    assertArrayEquals(new int[] {1, 2, 3}, (int[]) mockResult.included("topicIds"));
    assertEquals(10, mockResult.included("fromForumId"));
    assertEquals("return path", mockResult.included("returnUrl"));
    assertEquals(new ArrayList<Category>(), mockResult.included("categories"));
  }
  @SuppressWarnings("deprecation")
  @Test
  public void chekGetAllRows() {

    SQLSourceHelper sqlSourceHelper = new SQLSourceHelper(context, "Source Name");
    List<List<Object>> queryResult = new ArrayList<List<Object>>(2);
    List<String[]> expectedResult = new ArrayList<String[]>(2);
    String string1 = "string1";
    String string2 = "string2";
    int int1 = 1;
    int int2 = 2;
    Date date1 = new Date(115, 0, 1);
    Date date2 = new Date(115, 1, 2);

    List<Object> row1 = new ArrayList<Object>(3);
    String[] expectedRow1 = new String[3];
    row1.add(string1);
    expectedRow1[0] = string1;
    row1.add(int1);
    expectedRow1[1] = Integer.toString(int1);
    row1.add(date1);
    expectedRow1[2] = date1.toString();
    queryResult.add(row1);
    expectedResult.add(expectedRow1);

    List<Object> row2 = new ArrayList<Object>(3);
    String[] expectedRow2 = new String[3];
    row2.add(string2);
    expectedRow2[0] = string2;
    row2.add(int2);
    expectedRow2[1] = Integer.toString(int2);
    row2.add(date2);
    expectedRow2[2] = date2.toString();
    queryResult.add(row2);
    expectedResult.add(expectedRow2);

    assertArrayEquals(expectedResult.get(0), sqlSourceHelper.getAllRows(queryResult).get(0));
    assertArrayEquals(expectedResult.get(1), sqlSourceHelper.getAllRows(queryResult).get(1));
  }
  @Test
  public void getChildrenForProjectReturnsResourceGroups() {
    when(project.getResources(anyString())).thenReturn(new ArrayList<IResource>());

    ResourceGrouping[] groups =
        new ResourceGrouping[] {
          new ResourceGrouping(ResourceKind.BUILD_CONFIG, project),
          new ResourceGrouping(ResourceKind.DEPLOYMENT_CONFIG, project),
          new ResourceGrouping(ResourceKind.SERVICE, project),
          new ResourceGrouping(ResourceKind.POD, project),
          new ResourceGrouping(ResourceKind.REPLICATION_CONTROLLER, project),
          new ResourceGrouping(ResourceKind.BUILD, project),
          new ResourceGrouping(ResourceKind.IMAGE_STREAM, project),
          new ResourceGrouping(ResourceKind.ROUTE, project),
        };

    Object[] children = provider.getChildrenFor(project);
    assertArrayEquals("Exp. to get a set of resource groups for a project", groups, children);
  }
  @Test
  public void testUseTempDirectories() throws Exception {
    File dir1 = new File(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString());
    File dir2 = new File(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString());

    File[] tempDirs = new File[] {dir1, dir2};

    try {
      assertTrue(dir1.mkdirs());
      assertTrue(dir2.mkdirs());

      RocksDBStateBackend rocksDbBackend = new RocksDBStateBackend(TEMP_URI);
      assertNull(rocksDbBackend.getDbStoragePaths());

      rocksDbBackend.initializeForJob(
          getMockEnvironment(tempDirs), "foobar", IntSerializer.INSTANCE);
      assertArrayEquals(tempDirs, rocksDbBackend.getStoragePaths());
    } finally {
      FileUtils.deleteDirectory(dir1);
      FileUtils.deleteDirectory(dir2);
    }
  }