AlarmMapper { public Alarm mapNewAlarmFormToSeyren(Alarm newAlarm) throws CerebroException { alarmValidator.validateAlarm(newAlarm); newAlarm.setId(null); newAlarm.setLastCheck(null); if (newAlarm.getFrom() == null || newAlarm.getFrom().isEmpty()) { newAlarm.setFrom(DEFAULT_FROM); } if (newAlarm.getUntil() == null || newAlarm.getUntil().isEmpty()) { newAlarm.setUntil(DEFAULT_UNTIL); } updateSourcesToBackend(newAlarm); initListSubscription(newAlarm); return newAlarm; }  Alarm.Alarms mapToPresentation(Alarm.Alarms alarms); Collection<Alarm> mapToPresentation(final Collection<Alarm> alarms); Alarm mapToPresentation(Alarm alarm); Alarm mapNewAlarmFormToSeyren(Alarm newAlarm); Alarm mapUpdateAlarmFormToSeyren(final Alarm updatedAlarm); static final String DEFAULT_FROM; static final String DEFAULT_UNTIL; }
@Test public void testMapNewAlarmFormToSeyrenOK() throws Exception { alarmMapper.mapNewAlarmFormToSeyren(this.defaultAlarm); verify(alarmValidator).validateAlarm(this.defaultAlarm); this.defaultAlarm.getSubscriptions() .forEach(subscription -> verify(subscriptionMapper).mapNewSubscriptionFormToSeyren(subscription)); }
@Test public void testSetNullFromUntilTimeToDefaultValues() throws Exception { Alarm c = this.defaultAlarm; c.setFrom(null); c.setUntil(null); c = alarmMapper.mapNewAlarmFormToSeyren(c); assertEquals(alarmMapper.DEFAULT_FROM, c.getFrom()); assertEquals(alarmMapper.DEFAULT_UNTIL, c.getUntil()); }
@Test public void testSetEmptyFromUntilTimeToDefaultValues() throws Exception { Alarm c = this.defaultAlarm; c.setFrom(""); c.setUntil(""); c = alarmMapper.mapNewAlarmFormToSeyren(c); assertEquals(AlarmMapper.DEFAULT_FROM, c.getFrom()); assertEquals(AlarmMapper.DEFAULT_UNTIL, c.getUntil()); }
@Test public void testNoFrontendUrlWithNoMapping() throws Exception { Map<URI, URI> emptyMap = new HashMap<>(); when(graphiteSources.getIpportsByUrl()).thenReturn(new HashMap<>()); when(this.graphiteSources.getSources()).thenReturn(new ArrayList<GraphiteSources.GraphiteSource>()); Alarm frontendAlarm = TestUtils.getDefaultAlarm(); frontendAlarm.setGraphiteBaseUrl(null); Alarm backendAlarm = alarmMapper.mapNewAlarmFormToSeyren(frontendAlarm); assertEquals(null, backendAlarm.getGraphiteBaseUrl()); }
@Test public void testNoFrontendUrlWithSingleUrl() throws Exception { Map<URI, URI> emptyMap = new HashMap<>(); when(graphiteSources.getIpportsByUrl()).thenReturn(new HashMap<>()); when(this.graphiteSources.getSources()).thenReturn(Stream.of(new GraphiteSources.GraphiteSource(DEFAULT_GRAPHITE_URL)).collect(Collectors.toList())); Alarm frontendAlarm = TestUtils.getDefaultAlarm(); frontendAlarm.setGraphiteBaseUrl(null); Alarm backendAlarm = alarmMapper.mapNewAlarmFormToSeyren(frontendAlarm); assertEquals(DEFAULT_GRAPHITE_URL, backendAlarm.getGraphiteBaseUrl()); }
@Test public void testNoFrontendUrlWithMultipleUrl() throws Exception { Map<URI, URI> emptyMap = new HashMap<>(); when(graphiteSources.getIpportsByUrl()).thenReturn(new HashMap<>()); when(this.graphiteSources.getSources()).thenReturn( Stream.of(new GraphiteSources.GraphiteSource(DEFAULT_GRAPHITE_URL), new GraphiteSources.GraphiteSource(OTHER_GRAPHITE_URL)) .collect(Collectors.toList())); when(this.graphiteSources.getSources()).thenReturn(new ArrayList<GraphiteSources.GraphiteSource>()); Alarm frontendAlarm = TestUtils.getDefaultAlarm(); frontendAlarm.setGraphiteBaseUrl(null); Alarm backendAlarm = alarmMapper.mapNewAlarmFormToSeyren(frontendAlarm); assertEquals(null, backendAlarm.getGraphiteBaseUrl()); }
@Test public void testNoFrontendUrlWithSingleUrlIpport() throws Exception { Map<URI, URI> ipports = new HashMap<>(); ipports.put(DEFAULT_GRAPHITE_URL, DEFAULT_GRAPHITE_IPPORT); when(graphiteSources.getIpportsByUrl()).thenReturn(ipports); when(this.graphiteSources.getSources()).thenReturn( Stream.of(new GraphiteSources.GraphiteSource(DEFAULT_GRAPHITE_URL, DEFAULT_GRAPHITE_IPPORT)).collect(Collectors.toList())); Alarm frontendAlarm = TestUtils.getDefaultAlarm(); frontendAlarm.setGraphiteBaseUrl(null); Alarm backendAlarm = alarmMapper.mapNewAlarmFormToSeyren(frontendAlarm); assertEquals(DEFAULT_GRAPHITE_IPPORT, backendAlarm.getGraphiteBaseUrl()); }
@Test public void testNoFrontendUrlWithMultipleUrlIpport() throws Exception { Map<URI, URI> ipports = new HashMap<>(); ipports.put(DEFAULT_GRAPHITE_URL, DEFAULT_GRAPHITE_IPPORT); ipports.put(OTHER_GRAPHITE_URL, OTHER_GRAPHITE_IPPORT); when(graphiteSources.getIpportsByUrl()).thenReturn(ipports); when(this.graphiteSources.getSources()).thenReturn(Stream .of(new GraphiteSources.GraphiteSource(DEFAULT_GRAPHITE_URL, DEFAULT_GRAPHITE_IPPORT), new GraphiteSources.GraphiteSource(OTHER_GRAPHITE_URL, OTHER_GRAPHITE_IPPORT)).collect(Collectors.toList())); Alarm frontendAlarm = TestUtils.getDefaultAlarm(); frontendAlarm.setGraphiteBaseUrl(null); Alarm backendAlarm = alarmMapper.mapNewAlarmFormToSeyren(frontendAlarm); assertEquals(OTHER_GRAPHITE_IPPORT, backendAlarm.getGraphiteBaseUrl()); }
@Test public void testFrontendUrlWithNoMapping() throws Exception { Map<URI, URI> emptyMap = new HashMap<>(); when(graphiteSources.getIpportsByUrl()).thenReturn(new HashMap<>()); when(this.graphiteSources.getSources()).thenReturn(new ArrayList<GraphiteSources.GraphiteSource>()); Alarm frontendAlarm = TestUtils.getDefaultAlarm(); frontendAlarm.setGraphiteBaseUrl(DEFAULT_GRAPHITE_URL); Alarm backendAlarm = alarmMapper.mapNewAlarmFormToSeyren(frontendAlarm); assertEquals(DEFAULT_GRAPHITE_URL, backendAlarm.getGraphiteBaseUrl()); }
@Test public void testFrontendUrlWithSingleUrl() throws Exception { Map<URI, URI> emptyMap = new HashMap<>(); when(graphiteSources.getIpportsByUrl()).thenReturn(new HashMap<>()); when(this.graphiteSources.getSources()).thenReturn(Stream.of(new GraphiteSources.GraphiteSource(DEFAULT_GRAPHITE_URL)).collect(Collectors.toList())); Alarm frontendAlarm = TestUtils.getDefaultAlarm(); frontendAlarm.setGraphiteBaseUrl(DEFAULT_GRAPHITE_URL); Alarm backendAlarm = alarmMapper.mapNewAlarmFormToSeyren(frontendAlarm); assertEquals(DEFAULT_GRAPHITE_URL, backendAlarm.getGraphiteBaseUrl()); }
@Test public void testFrontendUrlWithMultipleUrl() throws Exception { Map<URI, URI> emptyMap = new HashMap<>(); when(graphiteSources.getIpportsByUrl()).thenReturn(new HashMap<>()); when(this.graphiteSources.getSources()).thenReturn( Stream.of(new GraphiteSources.GraphiteSource(DEFAULT_GRAPHITE_URL), new GraphiteSources.GraphiteSource(OTHER_GRAPHITE_URL)) .collect(Collectors.toList())); when(this.graphiteSources.getSources()).thenReturn(new ArrayList<GraphiteSources.GraphiteSource>()); Alarm frontendAlarm = TestUtils.getDefaultAlarm(); frontendAlarm.setGraphiteBaseUrl(DEFAULT_GRAPHITE_URL); Alarm backendAlarm = alarmMapper.mapNewAlarmFormToSeyren(frontendAlarm); assertEquals(DEFAULT_GRAPHITE_URL, backendAlarm.getGraphiteBaseUrl()); }
@Test public void testFrontendUrlWithSingleUrlIpport() throws Exception { Map<URI, URI> ipports = new HashMap<>(); ipports.put(DEFAULT_GRAPHITE_URL, DEFAULT_GRAPHITE_IPPORT); when(graphiteSources.getIpportsByUrl()).thenReturn(ipports); when(this.graphiteSources.getSources()).thenReturn( Stream.of(new GraphiteSources.GraphiteSource(DEFAULT_GRAPHITE_URL, DEFAULT_GRAPHITE_IPPORT)).collect(Collectors.toList())); Alarm frontendAlarm = TestUtils.getDefaultAlarm(); frontendAlarm.setGraphiteBaseUrl(DEFAULT_GRAPHITE_URL); Alarm backendAlarm = alarmMapper.mapNewAlarmFormToSeyren(frontendAlarm); assertEquals(DEFAULT_GRAPHITE_IPPORT, backendAlarm.getGraphiteBaseUrl()); }
@Test public void testFrontendUrlWithMultipleUrlIpport() throws Exception { Map<URI, URI> ipports = new HashMap<>(); ipports.put(DEFAULT_GRAPHITE_URL, DEFAULT_GRAPHITE_IPPORT); ipports.put(OTHER_GRAPHITE_URL, OTHER_GRAPHITE_IPPORT); when(graphiteSources.getIpportsByUrl()).thenReturn(ipports); when(this.graphiteSources.getSources()).thenReturn(Stream .of(new GraphiteSources.GraphiteSource(DEFAULT_GRAPHITE_URL, DEFAULT_GRAPHITE_IPPORT), new GraphiteSources.GraphiteSource(OTHER_GRAPHITE_URL, OTHER_GRAPHITE_IPPORT)).collect(Collectors.toList())); Alarm frontendAlarm = TestUtils.getDefaultAlarm(); frontendAlarm.setGraphiteBaseUrl(OTHER_GRAPHITE_URL); Alarm backendAlarm = alarmMapper.mapNewAlarmFormToSeyren(frontendAlarm); assertEquals(OTHER_GRAPHITE_IPPORT, backendAlarm.getGraphiteBaseUrl()); }
@Test public void testUnknownFrontendUrlWithNoMapping() throws Exception { Map<URI, URI> emptyMap = new HashMap<>(); when(graphiteSources.getIpportsByUrl()).thenReturn(new HashMap<>()); when(this.graphiteSources.getSources()).thenReturn(new ArrayList<GraphiteSources.GraphiteSource>()); Alarm frontendAlarm = TestUtils.getDefaultAlarm(); frontendAlarm.setGraphiteBaseUrl(OTHER_GRAPHITE_URL); Alarm backendAlarm = alarmMapper.mapNewAlarmFormToSeyren(frontendAlarm); assertEquals(OTHER_GRAPHITE_URL, backendAlarm.getGraphiteBaseUrl()); }
@Test public void testUnknownFrontendUrlWithSingleUrl() throws Exception { Map<URI, URI> emptyMap = new HashMap<>(); when(graphiteSources.getIpportsByUrl()).thenReturn(new HashMap<>()); when(this.graphiteSources.getSources()).thenReturn(Stream.of(new GraphiteSources.GraphiteSource(DEFAULT_GRAPHITE_URL)).collect(Collectors.toList())); Alarm frontendAlarm = TestUtils.getDefaultAlarm(); frontendAlarm.setGraphiteBaseUrl(OTHER_GRAPHITE_URL); Alarm backendAlarm = alarmMapper.mapNewAlarmFormToSeyren(frontendAlarm); assertEquals(OTHER_GRAPHITE_URL, backendAlarm.getGraphiteBaseUrl()); }
@Test public void testUnknownFrontendUrlWithSingleUrlIpport() throws Exception { Map<URI, URI> ipports = new HashMap<>(); ipports.put(DEFAULT_GRAPHITE_URL, DEFAULT_GRAPHITE_URL); when(graphiteSources.getIpportsByUrl()).thenReturn(ipports); when(this.graphiteSources.getSources()).thenReturn( Stream.of(new GraphiteSources.GraphiteSource(DEFAULT_GRAPHITE_URL, DEFAULT_GRAPHITE_IPPORT)).collect(Collectors.toList())); Alarm frontendAlarm = TestUtils.getDefaultAlarm(); frontendAlarm.setGraphiteBaseUrl(OTHER_GRAPHITE_URL); Alarm backendAlarm = alarmMapper.mapNewAlarmFormToSeyren(frontendAlarm); assertEquals(OTHER_GRAPHITE_URL, backendAlarm.getGraphiteBaseUrl()); }