refactoring and added controller functions

This commit is contained in:
yannick.blanken@csc-online.eu 2022-06-01 09:31:36 +02:00
parent e146f672b7
commit 9220951be6
9 changed files with 79 additions and 7 deletions

View File

@ -22,7 +22,7 @@ import static eu.csc.ODPAppVehOwnServer.com.WebSecurityConstants.Basic_PREFIX;
public class JwtAuthenticationTokenFilter extends OncePerRequestFilter {
private static Logger logger = Logger.getLogger(JwtAuthenticationTokenFilter.class.getSimpleName());
private static final Logger logger = Logger.getLogger(JwtAuthenticationTokenFilter.class.getSimpleName());
@Value("${jwt.header}")
private String tokenHeader;

View File

@ -1,5 +1,6 @@
package eu.csc.ODPAppVehOwnServer.controller.registration;
import eu.csc.ODPAppVehOwnServer.com.JwtAuthenticationTokenFilter;
import eu.csc.ODPAppVehOwnServer.controller.AbstractRestController;
import eu.csc.ODPAppVehOwnServer.models.data.DeviceDto;
import eu.csc.ODPAppVehOwnServer.persistence.services.CustomerService;
@ -9,10 +10,13 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.logging.Logger;
@RestController
@RequestMapping("reg/devices")
public class DeviceRegistrationController extends AbstractRestController {
private static final Logger logger = Logger.getLogger(DeviceRegistrationController.class.getSimpleName());
@Autowired
private DeviceService deviceService;

View File

@ -12,11 +12,14 @@ import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
@RestController
@RequestMapping("reg/vehicles")
public class VehicleRegistrationController extends AbstractRestController {
private static final Logger logger = Logger.getLogger(VehicleRegistrationController.class.getSimpleName());
@Autowired
private CustomerService customerService;

View File

@ -8,6 +8,7 @@ import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.web.server.LocalServerPort;
public abstract class AbstractConfigControllerTester {
@Autowired
protected TestRestTemplate restTemplate;
protected String url;

View File

@ -0,0 +1,23 @@
package eu.csc.ODPAppVehOwnServer.web.clients;
import eu.csc.ODPAppVehOwnServer.client.clients.VehOwnAppClient;
import org.springframework.boot.web.server.LocalServerPort;
public abstract class AbstractClientTester {
@LocalServerPort
protected int port;
protected String url;
protected VehOwnAppClient client;
protected String token;
protected String user;
protected String password;
public AbstractClientTester(){
this.user ="test@test.test";
this.password = "yannyann1";
}
}

View File

@ -0,0 +1,35 @@
package eu.csc.ODPAppVehOwnServer.web.clients;
import eu.csc.ODPAppVehOwnServer.ODPAppVehOwnServerApplication;
import eu.csc.ODPAppVehOwnServer.client.ClientFactory;
import lombok.var;
import org.junit.jupiter.api.*;
import org.springframework.boot.test.context.SpringBootTest;
import java.io.IOException;
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = ODPAppVehOwnServerApplication.class)
public class CustomerClientTester extends AbstractClientTester{
@BeforeEach
void init() throws IOException {
this.url = "http://localhost:" + port;
this.token = ClientFactory.authenticate(url, this.user, this.password).body().getToken();
client = ClientFactory.createVehOwnAppClient(this.url, this.token);
}
@Test
void testLoggin(){
Assertions.assertNotNull(this.client);
var result = Assertions.assertDoesNotThrow(() ->
client.listCustomerDevices());
Assertions.assertNotNull(result);
}
}

View File

@ -38,10 +38,16 @@ public class ClientFactory {
public static AuthenticationService createAuthenticationService(String url) {
return createService(url, AuthenticationService.class);
} public static VehOwnAppClient createVehOwnAppClient(String url) {
}
public static VehOwnAppClient createVehOwnAppClient(String url) {
return new VehOwnAppClient(url);
}
public static VehOwnAppClient createVehOwnAppClient(String url, String token) {
return new VehOwnAppClient(url, token);
}
public static <S> S createService(String url, Class<S> serviceClass, String user, String password) {

View File

@ -21,7 +21,7 @@ public interface IDataClient {
CallResponse<List<DeviceDto>> listDevices() throws IOException;
List<VehicleModelDto> listVehicleModels() throws IOException;
List<VehicleModelDto> listVehicleModels(VehicleBrandDto brand) throws IOException;
List<VehicleModelDto> listVehicleModels(String brand) throws IOException;
//region Customer

View File

@ -68,8 +68,8 @@ public class VehOwnAppClient extends AbstractClient implements IDataClient {
}
@Override
public List<VehicleModelDto> listVehicleModels(VehicleBrandDto brand) throws IOException {
throw new UnsupportedOperationException();
public List<VehicleModelDto> listVehicleModels(String brand) throws IOException {
return executeCall(clientService.listVehicleModelsByBrand(brand)).getBody();
}
@Override
@ -90,12 +90,12 @@ public class VehOwnAppClient extends AbstractClient implements IDataClient {
@Override
public CustomerDeviceDto registerCustomerDevice(CustomerDeviceDto body) throws IOException {
return null;
return executeCall(customerService.registerCustomerDevices(body)).getBody();
}
@Override
public List<CustomerDeviceDto> listCustomerDevices() throws IOException {
return null;
return executeCall(customerService.listCustomerDevices()).getBody();
}
//endregion