Commit 051948f5 authored by Dimitrios Chalepakis's avatar Dimitrios Chalepakis
Browse files

SI-442 Unit Tests jobmanager, exception, controller added


Signed-off-by: Dimitrios Chalepakis's avatarDimitrios Chalepakis <dimitrios.chalepakis@pta.de>
parent 916a68bd
......@@ -72,7 +72,6 @@ public class AddressService {
} catch (Exception ex) {
ex.printStackTrace();
log.warn("Adresse [sdo_x1= " + addressDto.getSdox1()
+ ", sdo_y1= " + addressDto.getSdoy1()
+ ", g3e_fid=" + addressDto.getG3efid()
......
......@@ -15,6 +15,7 @@
package org.eclipse.openk.gridfailureinformation.importadresses.config;
import org.eclipse.openk.gridfailureinformation.importadresses.AddressImportApplication;
import org.eclipse.openk.gridfailureinformation.importadresses.jobs.JobManager;
import org.eclipse.openk.gridfailureinformation.importadresses.mapper.AddressMapper;
import org.eclipse.openk.gridfailureinformation.importadresses.mapper.AddressMapperImpl;
import org.eclipse.openk.gridfailureinformation.importadresses.mapper.StationMapper;
......@@ -55,4 +56,7 @@ public class TestConfiguration {
@Bean
public StationService myStationService() { return new StationService(); }
@Bean
public JobManager jobManager() { return new JobManager(); }
}
/*
*******************************************************************************
* Copyright (c) 2018 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************
*/
package org.eclipse.openk.gridfailureinformation.importadresses.controller;
import org.eclipse.openk.gridfailureinformation.importadresses.AddressImportApplication;
import org.eclipse.openk.gridfailureinformation.importadresses.jobs.JobManager;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.web.servlet.MockMvc;
import static org.mockito.Mockito.verify;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@SpringBootTest(classes = AddressImportApplication.class)
@AutoConfigureMockMvc
@ActiveProfiles("test")
public class AddressImportControllerTest {
@MockBean
private JobManager jobManager;
@Autowired
private MockMvc mockMvc;
@Test
public void shouldTriggerStartImport() throws Exception {
mockMvc.perform(post("/addresses/import"))
.andExpect(status().is2xxSuccessful());
verify(jobManager).triggerStartImport();
}
}
/*
*******************************************************************************
* Copyright (c) 2018 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************
*/
package org.eclipse.openk.gridfailureinformation.importadresses.exceptions;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class InternalServerErrorExceptionTest {
@Test
public void testExceptionCreationForCoverage() {
new InternalServerErrorException("testOnly");
Exception innerException = new InternalServerErrorException("inner Exception");
assertEquals( innerException.getMessage(), "inner Exception");
}
}
/*
*******************************************************************************
* Copyright (c) 2018 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************
*/
package org.eclipse.openk.gridfailureinformation.importadresses.jobs;
import org.eclipse.openk.gridfailureinformation.importadresses.config.TestConfiguration;
import org.eclipse.openk.gridfailureinformation.importadresses.service.AddressImportService;
import org.junit.jupiter.api.Test;
import org.powermock.reflect.Whitebox;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.ContextConfiguration;
import static java.lang.Boolean.TRUE;
import static java.lang.Boolean.FALSE;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
@DataJpaTest
@ContextConfiguration(classes = {TestConfiguration.class})
public class JobManagerTest {
@Autowired
JobManager jobManager;
@MockBean
AddressImportService addressImportService;
@Test
public void shouldTriggerStartImport() {
jobManager.triggerStartImport();
Boolean startImport = Whitebox.getInternalState(jobManager, "startImport");
assertEquals(startImport, TRUE);
}
@Test
public void shouldImportOnTriggerAndSetStartImportBackToFalse() throws Exception {
Whitebox.setInternalState(jobManager, "startImport", TRUE);
try {
Whitebox.invokeMethod(jobManager, "importOnTrigger");
} catch (Exception e) {
e.printStackTrace();
}
Boolean startImport = Whitebox.getInternalState(jobManager, "startImport");
assertEquals(startImport, FALSE);
}
@Test
public void shouldImportOnTriggerAndDontChangeTheValueFromStartImport() {
Whitebox.setInternalState(jobManager, "startImport", FALSE);
try {
Whitebox.invokeMethod(jobManager, "importOnTrigger");
} catch (Exception e) {
e.printStackTrace();
}
Boolean startImport = Whitebox.getInternalState(jobManager, "startImport");
assertEquals(startImport, FALSE);
}
@Test
public void shouldImportAddressdataAndInvokeImportAddresses() {
jobManager.cleanUp = false;
try {
Whitebox.invokeMethod(jobManager, "importAddressdata");
} catch (Exception e) {
e.printStackTrace();
}
verify(addressImportService, times(1)).importAddresses(false);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment