SeyrenRepository { public Alarm getAlarm(final String id) { try { return restTemplate.getForObject(seyrenUrl + API_ALARMS + "/" + id, Alarm.class); } catch (final HttpStatusCodeException exception) { throw new SeyrenException("getAlarm", exception.getStatusCode().value()); } catch (final ResourceAccessException exception) { throw new CerebroException(ErrorCode.ALARM_UNKNOWN, "Alarm with id '" + id + "' not found", exception); } }  void setRestTemplate(final RestTemplate restTemplate); void setSeyrenUrl(final String seyrenUrl); Alarm getAlarm(final String id); Alarm.Alarms getAllAlarms(); void addAlarm(final Alarm alarm); void updateAlarm(final Alarm alarm); boolean deleteAlarm(final String alarmId); void addSubscription(final Subscription subscription, final String alarmId); void updateSubscription(final Subscription subscription, final String alarmId); boolean deleteSubscription(final String alarmId, final String subscriptionId); Alert.Alerts getAlerts(final int start, final int items); Alert.Alerts getAlarmAlerts(final String alarmId, final int start, final int items); static final String API_ALARMS; static final String API_ALERTS; }
@Test public void testGetAlarmOK() throws Exception { Alarm alarm = repository.getAlarm(TestUtils.DEFAULT_ALARM_ID); assertEquals(TestUtils.DEFAULT_ALARM_ID, alarm.getId()); }
@Test public void testGetAlarmFailIfAlarmNotFound() { when(restTemplate.getForObject(anyString(), eq(Alarm.class))).thenThrow(new ResourceAccessException("coucou")); try { repository.getAlarm("coucou"); fail(); } catch (CerebroException e) { assertEquals(ErrorCode.ALARM_UNKNOWN, e.getErrorCode()); } }