UpgradeStatus { public boolean isExecuted(InstallContext ctx, UpgradeInfo info, UpgradeAction action) throws RepositoryException { Node infoStatus = getInfoStatus(info); String actionId = buildActionId(action); if (infoStatus.hasProperty(PN_ACTIONS)) { for (Value executedAction : infoStatus.getProperty(PN_ACTIONS).getValues()) { if (executedAction.getString().equals(actionId)) { LOG.debug(ctx, "action [{}] already exected: [{}]", actionId, infoStatus); return true; } } } LOG.debug(ctx, "action [{}] not exected yet: [{}]", actionId, infoStatus); return false; } UpgradeStatus(InstallContext ctx, String path); boolean isExecuted(InstallContext ctx, UpgradeInfo info, UpgradeAction action); void update(InstallContext ctx, boolean failed); void update(InstallContext ctx, UpgradeInfo info); @Override String toString(); Node getNode(); Version getVersion(); static final String PN_UPGRADE_TIME; static final String PN_VERSION; static final String PN_STATUS; static final String PN_ACTIONS; }
@Test public void testIsExecuted() throws Exception { Mockito.when(info.getNode().getName()).thenReturn("testInfo"); Mockito.when(action.getName()).thenReturn("testName"); Mockito.when(action.getContentHash()).thenReturn("testHash"); Assert.assertFalse(status.isExecuted(ctx, info, action)); sling.build().resource("/test/testInfo"); Assert.assertFalse(status.isExecuted(ctx, info, action)); sling.build().resource("/test/testInfo", UpgradeStatus.PN_ACTIONS, new String[] { "testName_testHash", "anotherTest" }); Assert.assertTrue(status.isExecuted(ctx, info, action)); Mockito.when(action.getName()).thenReturn("anotherTest"); Assert.assertFalse(status.isExecuted(ctx, info, action)); }