use of org.ligoj.app.api.SubscriptionStatusWithData in project ligoj-api by ligoj.
the class SubscriptionResource method refreshSubscription.
/**
* Refresh given subscriptions and return their status.
*/
private SubscriptionStatusWithData refreshSubscription(final Subscription subscription) {
final Map<String, String> parameters = getParameters(subscription.getId());
final SubscriptionStatusWithData statusWithData = nodeResource.checkSubscriptionStatus(subscription, parameters);
statusWithData.setId(subscription.getId());
statusWithData.setProject(subscription.getProject().getId());
statusWithData.setParameters(parameterValueResource.getNonSecuredSubscriptionParameters(subscription.getId()));
// Update the last event with fresh data
eventResource.registerEvent(subscription, EventType.STATUS, statusWithData.getStatus().name());
// Return the fresh statuses
return statusWithData;
}
use of org.ligoj.app.api.SubscriptionStatusWithData in project ligoj-api by ligoj.
the class SubscriptionResourceTest method refreshStatuses.
@Test
public void refreshStatuses() throws IOException {
persistEntities("csv", new Class[] { Event.class }, StandardCharsets.UTF_8.name());
final int projectId = projectRepository.findByName("MDA").getId();
final Map<Integer, EventVo> subscriptionStatus = resource.getStatusByProject(projectId);
Assertions.assertEquals(1, subscriptionStatus.size());
final Map<Integer, SubscriptionStatusWithData> statuses = resource.refreshStatuses(Collections.singleton(subscription));
Assertions.assertEquals(1, statuses.size());
final SubscriptionStatusWithData status = statuses.get(subscription);
Assertions.assertEquals(subscription, status.getId().intValue());
Assertions.assertEquals(NodeStatus.UP, status.getStatus());
Assertions.assertEquals("service:bt:jira:4", status.getNode());
Assertions.assertEquals(projectId, status.getProject().intValue());
Assertions.assertNotNull(status.getParameters());
Assertions.assertEquals(3, status.getParameters().size());
Assertions.assertEquals("10074", status.getParameters().get("service:bt:jira:project"));
Assertions.assertEquals("MDA", status.getParameters().get("service:bt:jira:pkey"));
Assertions.assertEquals("http://localhost:8120", status.getParameters().get("service:bt:jira:url"));
}
use of org.ligoj.app.api.SubscriptionStatusWithData in project ligoj-api by ligoj.
the class NodeResourceTest method prepareSubscriptionsEvent.
private long prepareSubscriptionsEvent() throws Exception {
// Check previous status
final long eventsCount = eventRepository.count();
Assertions.assertEquals(5, eventsCount);
final ServicePluginLocator servicePluginLocator = resourceMock.locator;
// Service is up --> SONAR
final SonarPluginResource sonar = Mockito.mock(SonarPluginResource.class);
Mockito.when(servicePluginLocator.getResource(ArgumentMatchers.anyString(), ArgumentMatchers.eq(ToolPlugin.class))).thenReturn(sonar);
Mockito.when(servicePluginLocator.getResourceExpected(ArgumentMatchers.anyString(), ArgumentMatchers.eq(ToolPlugin.class))).thenReturn(sonar);
Mockito.when(sonar.checkSubscriptionStatus(ArgumentMatchers.anyInt(), ArgumentMatchers.anyString(), ArgumentMatchers.anyMap())).thenReturn(new SubscriptionStatusWithData());
Mockito.when(sonar.checkStatus(ArgumentMatchers.anyString(), ArgumentMatchers.anyMap())).thenReturn(true);
// Service is down --> JIRA
final JiraPluginResource jira = Mockito.mock(JiraPluginResource.class);
Mockito.when(servicePluginLocator.getResource(ArgumentMatchers.contains(":jira"), ArgumentMatchers.eq(ToolPlugin.class))).thenReturn(jira);
Mockito.when(servicePluginLocator.getResourceExpected(ArgumentMatchers.contains(":jira"), ArgumentMatchers.eq(ToolPlugin.class))).thenReturn(jira);
Mockito.when(jira.checkSubscriptionStatus(ArgumentMatchers.anyInt(), ArgumentMatchers.anyString(), ArgumentMatchers.anyMap())).thenReturn(new SubscriptionStatusWithData(false));
// Service throw an exception --> JENKINS
final JenkinsPluginResource jenkins = Mockito.mock(JenkinsPluginResource.class);
Mockito.when(servicePluginLocator.getResource(ArgumentMatchers.contains(":jenkins"), ArgumentMatchers.eq(ToolPlugin.class))).thenReturn(jenkins);
Mockito.when(servicePluginLocator.getResourceExpected(ArgumentMatchers.contains(":jenkins"), ArgumentMatchers.eq(ToolPlugin.class))).thenReturn(jenkins);
Mockito.when(jenkins.checkSubscriptionStatus(ArgumentMatchers.anyInt(), ArgumentMatchers.anyString(), ArgumentMatchers.anyMap())).thenThrow(new TechnicalException("junit"));
return eventsCount;
}
use of org.ligoj.app.api.SubscriptionStatusWithData in project ligoj-api by ligoj.
the class AbstractToolPluginResource method checkSubscriptionStatus.
@Override
public SubscriptionStatusWithData checkSubscriptionStatus(final Map<String, String> parameters) {
final SubscriptionStatusWithData status = new SubscriptionStatusWithData();
status.put("property", "value");
return status;
}
use of org.ligoj.app.api.SubscriptionStatusWithData in project ligoj-api by ligoj.
the class SubscriptionResourceTest method checkSubscriptionStatus.
@Test
public void checkSubscriptionStatus() {
JiraPluginResource service = servicePluginLocator.getResource("service:bt:jira:4", JiraPluginResource.class);
final SubscriptionStatusWithData status = service.checkSubscriptionStatus(null);
Assertions.assertNotNull(status);
Assertions.assertEquals("value", status.getData().get("property"));
}
Aggregations