org.powermock.reflect.internal.WhiteboxImpl Java Examples

The following examples show how to use org.powermock.reflect.internal.WhiteboxImpl. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LeaderElectionServiceTest.java    From cloudbreak with Apache License 2.0 7 votes vote down vote up
@Test
public void testExecuteMissedTimeBasedAlertsNeed() throws Exception {
    ZonedDateTime now = ZonedDateTime.now();
    when(dateTimeService.getDefaultZonedDateTime()).thenReturn(now);
    when(dateTimeService.getNextSecound(any())).thenReturn(now);
    Cluster cluster = new Cluster();
    cluster.setCoolDown(5);
    cluster.setLastEvaluated(2900L);
    TimeAlert timeAlert = new TimeAlert();
    cluster.setTimeAlerts(Collections.singleton(timeAlert));

    WhiteboxImpl.invokeMethod(underTest, "executeMissedTimeBasedAlerts", cluster);

    verify(applicationContext, times(1)).getBean(anyString(), eq(CronTimeEvaluator.class));

    Map<TimeAlert, ZonedDateTime> expectedAlerts = new LinkedHashMap<>();
    expectedAlerts.put(timeAlert, now);
    expectedAlerts.put(timeAlert, now);
    verify(cronTimeEvaluator, times(1)).publishIfNeeded(eq(expectedAlerts));
}
 
Example #2
Source File: SPChineseTokenizerTest.java    From thulac4j with Apache License 2.0 5 votes vote down vote up
@Test
public void setPreviousTrans() throws Exception {
	SPChineseTokenizer tokenizer = new SPChineseTokenizer(
			new FileInputStream(SEG_WEIGHTS_PATH),
			new FileInputStream(SEG_FEATURES_PATH),
			new FileInputStream(SEG_LABELS_PATH));
	StructuredPerceptronClassifier classifier = WhiteboxImpl.getInternalState(tokenizer, "classifier");
	int[][] previousTrans = WhiteboxImpl.invokeMethod(
			tokenizer,
			"setPreviousTransitions",
			new Class<?>[]{String[].class},
			(Object) classifier.getLabelValues());

	assertEquals("[[1, 2], [0, 3], [1, 2], [0, 3]]",
			Arrays.deepToString(previousTrans));

	tokenizer = new SPChineseTokenizer(
			new FileInputStream(POS_WEIGHTS_PATH),
			new FileInputStream(POS_FEATURES_PATH),
			new FileInputStream(POS_LABELS_PATH));
	classifier = WhiteboxImpl.getInternalState(tokenizer, "classifier");
	previousTrans = WhiteboxImpl.invokeMethod(
			tokenizer,
			"setPreviousTransitions",
			new Class<?>[]{String[].class},
			(Object) classifier.getLabelValues());
	assertEquals("[1, 2, 4, 5, 7, 10, 13, 15, 17, 18, 19, 23, 25, 27, " +
					"30, 32, 33, 34, 35, 36, 37, 38, 39, 41, 44, 45, 48, 50, 53, " +
					"56, 57, 59, 61, 63, 67, 69, 72, 74, 76, 80, 81, 82, 83, 88, " +
					"89, 90, 91, 95]",
			Arrays.toString(previousTrans[0]));
	assertEquals("[0, 20]", Arrays.toString(previousTrans[1]));
	assertEquals("[54, 55]", Arrays.toString(previousTrans[56]));
	assertEquals("[93, 94]", Arrays.toString(previousTrans[95]));
}
 
Example #3
Source File: LeaderElectionServiceTest.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Test
public void testIsExecutionOfMissedTimeBasedAlertsNeededNoPeriscopeNodeId() throws Exception {
    Cluster cluster = getValidIsMissedNeeded();
    cluster.setPeriscopeNodeId(null);

    boolean needed = WhiteboxImpl.invokeMethod(underTest, "isExecutionOfMissedTimeBasedAlertsNeeded", cluster);

    Assert.assertFalse(needed);
}
 
Example #4
Source File: LeaderElectionServiceTest.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Test
public void testIsExecutionOfMissedTimeBasedAlertsNeededNoAutoscaling() throws Exception {
    Cluster cluster = getValidIsMissedNeeded();
    cluster.setAutoscalingEnabled(false);

    boolean needed = WhiteboxImpl.invokeMethod(underTest, "isExecutionOfMissedTimeBasedAlertsNeeded", cluster);

    Assert.assertFalse(needed);
}
 
Example #5
Source File: LeaderElectionServiceTest.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Test
public void testIsExecutionOfMissedTimeBasedAlertsNeededLastScalingHappend() throws Exception {
    Cluster cluster = getValidIsMissedNeeded();
    cluster.setCoolDown(1);

    boolean needed = WhiteboxImpl.invokeMethod(underTest, "isExecutionOfMissedTimeBasedAlertsNeeded", cluster);

    Assert.assertFalse(needed);
}
 
Example #6
Source File: LeaderElectionServiceTest.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Test
public void testIsExecutionOfMissedTimeBasedAlertsNeededNoAlerts() throws Exception {
    Cluster cluster = getValidIsMissedNeeded();
    cluster.setTimeAlerts(null);

    boolean needed = WhiteboxImpl.invokeMethod(underTest, "isExecutionOfMissedTimeBasedAlertsNeeded", cluster);

    Assert.assertFalse(needed);
}
 
Example #7
Source File: LeaderElectionServiceTest.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Test
public void testIsExecutionOfMissedTimeBasedAlertsNeededTrue() throws Exception {
    Cluster cluster = getValidIsMissedNeeded();

    boolean needed = WhiteboxImpl.invokeMethod(underTest, "isExecutionOfMissedTimeBasedAlertsNeeded", cluster);

    Assert.assertTrue(needed);
}
 
Example #8
Source File: LeaderElectionServiceTest.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Test
public void testExecuteMissedTimeBasedAlertsNotNeedLastEvalLessThanRewind() throws Exception {
    Cluster cluster = new Cluster();
    cluster.setCoolDown(2);
    cluster.setLastEvaluated(4900L);
    cluster.setTimeAlerts(Collections.singleton(new TimeAlert()));

    WhiteboxImpl.invokeMethod(underTest, "executeMissedTimeBasedAlerts", cluster);

    verify(applicationContext, times(0)).getBean(anyString(), eq(CronTimeEvaluator.class));
    verify(cronTimeEvaluator, times(0)).publishIfNeeded(any(Map.class));
}
 
Example #9
Source File: LeaderElectionServiceTest.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Test
public void testExecuteMissedTimeBasedAlertsNotNeedCooldownLessThanRewind() throws Exception {
    Cluster cluster = new Cluster();
    cluster.setCoolDown(0);
    cluster.setLastEvaluated(1L);
    cluster.setTimeAlerts(Collections.singleton(new TimeAlert()));

    WhiteboxImpl.invokeMethod(underTest, "executeMissedTimeBasedAlerts", cluster);

    verify(applicationContext, times(0)).getBean(anyString(), eq(CronTimeEvaluator.class));
    verify(cronTimeEvaluator, times(0)).publishIfNeeded(any(Map.class));
}
 
Example #10
Source File: FilePickerProxyTest.java    From friendly-plans with GNU General Public License v3.0 4 votes vote down vote up
private Pattern getPattern(AssetType assetType) throws Exception {
    return WhiteboxImpl.invokeMethod(filePickerProxy, "getPattern", assetType);
}
 
Example #11
Source File: ClusterSyncManagerTest.java    From Decision with Apache License 2.0 4 votes vote down vote up
@Test
public void testManageBarrierResultsChildShouldBeKO() throws Exception {

    String barrierPath = "/stratio/decision/barrier";

    ActionCallbackDto parsedResponse = new ActionCallbackDto();
    parsedResponse.setDescription(ReplyCode.KO_GENERAL_ERROR.getMessage());
    parsedResponse.setErrorCode(ReplyCode.KO_GENERAL_ERROR.getCode());

    byte[] data = new Gson().toJson(parsedResponse).getBytes();

    when(curatorFramework.getData().forPath(anyString())).thenReturn(data);

    final ClusterSyncManager spyClusterSyncManager = PowerMockito.spy(new ClusterSyncManager(STREAMING
            .ZK_CLUSTER_MANAGER_PATH, "id", configurationContext, failOverTask, curatorFramework, zkUtils,
            clusterBarrierManager));


    ActionCallbackDto reply = WhiteboxImpl.invokeMethod(spyClusterSyncManager, "manageBarrierResults", message,
            nodeReply, barrierPath, true);

    Assert.assertEquals(ReplyCode.KO_GENERAL_ERROR.getCode(), reply.getErrorCode());
}
 
Example #12
Source File: ClusterSyncManagerTest.java    From Decision with Apache License 2.0 4 votes vote down vote up
@Test
public void testManageBarrierResultsChildShouldBeOK() throws Exception {

    String barrierPath = "/stratio/decision/barrier";

    ActionCallbackDto parsedResponse = new ActionCallbackDto();
    parsedResponse.setDescription(ReplyCode.OK.getMessage());
    parsedResponse.setErrorCode(ReplyCode.OK.getCode());

    byte[] data = new Gson().toJson(parsedResponse).getBytes();

    when(curatorFramework.getData().forPath(anyString())).thenReturn(data);

    final ClusterSyncManager spyClusterSyncManager = PowerMockito.spy(new ClusterSyncManager(STREAMING
            .ZK_CLUSTER_MANAGER_PATH, "id", configurationContext, failOverTask, curatorFramework, zkUtils,
            clusterBarrierManager));


    ActionCallbackDto reply = WhiteboxImpl.invokeMethod(spyClusterSyncManager, "manageBarrierResults", message,
            nodeReply, barrierPath, true);

    Assert.assertEquals(ReplyCode.OK.getCode(), reply.getErrorCode());
}
 
Example #13
Source File: ClusterSyncManagerTest.java    From Decision with Apache License 2.0 3 votes vote down vote up
@Test
public void testManageBarrierResultsShouldBeNodeNotReply() throws Exception {

    String barrierPath = "/stratio/decision/barrier";

    ActionCallbackDto reply = WhiteboxImpl.invokeMethod(clusterSyncManager, "manageBarrierResults", message,
            nodeReply, barrierPath, false);

    Assert.assertEquals(ReplyCode.KO_NODE_NOT_REPLY.getCode(), reply.getErrorCode());
}
 
Example #14
Source File: ClusterSyncManagerTest.java    From Decision with Apache License 2.0 3 votes vote down vote up
@Test
public void testManageBarrierResultsShouldBeKO() throws Exception {

    String barrierPath = "/stratio/decision/barrier";

    when(nodeReply.getErrorCode()).thenReturn(ReplyCode.KO_GENERAL_ERROR.getCode());
    when(nodeReply.getDescription()).thenReturn(ReplyCode.KO_GENERAL_ERROR.getMessage());

    ActionCallbackDto reply = WhiteboxImpl.invokeMethod(clusterSyncManager, "manageBarrierResults", message,
            nodeReply, barrierPath, true);

    Assert.assertEquals(ReplyCode.KO_GENERAL_ERROR.getCode(), reply.getErrorCode()) ;
}
 
Example #15
Source File: ClusterSyncManagerTest.java    From Decision with Apache License 2.0 3 votes vote down vote up
@Test
public void testManageBarrierResultsShouldBeOK() throws Exception {

    String barrierPath = "/stratio/decision/barrier";

    when(nodeReply.getErrorCode()).thenReturn(ReplyCode.KO_GENERAL_ERROR.getCode());
    when(nodeReply.getDescription()).thenReturn(ReplyCode.KO_GENERAL_ERROR.getMessage());

    ActionCallbackDto reply = WhiteboxImpl.invokeMethod(clusterSyncManager, "manageBarrierResults", message,
            nodeReply, barrierPath, true);

    Assert.assertEquals(ReplyCode.KO_GENERAL_ERROR.getCode(), reply.getErrorCode());
}