use of io.gravitee.definition.model.Proxy in project gravitee-management-rest-api by gravitee-io.
the class ApiResourceTest method shouldUpdateApi.
@Test
public void shouldUpdateApi() {
final UpdateApiEntity mockApi = new UpdateApiEntity();
mockApi.setVersion("v1");
mockApi.setDescription("Description of my API");
mockApi.setProxy(new Proxy());
doReturn(new ApiEntity()).when(apiService).update(API_NAME, mockApi);
final Response response = target(API_NAME).request().put(Entity.json(mockApi));
assertEquals(NO_CONTENT_204, response.getStatus());
}
use of io.gravitee.definition.model.Proxy in project gravitee-management-rest-api by gravitee-io.
the class ApiServiceImpl method create.
@Override
public ApiEntity create(NewApiEntity newApiEntity, String userId) throws ApiAlreadyExistsException {
UpdateApiEntity apiEntity = new UpdateApiEntity();
apiEntity.setName(newApiEntity.getName());
apiEntity.setDescription(newApiEntity.getDescription());
apiEntity.setVersion(newApiEntity.getVersion());
// check the existence of groups
if (newApiEntity.getGroups() != null && !newApiEntity.getGroups().isEmpty()) {
try {
groupService.findByIds(newApiEntity.getGroups());
} catch (GroupsNotFoundException gnfe) {
throw new InvalidDataException("Groups [" + newApiEntity.getGroups() + "] does not exist");
}
}
apiEntity.setGroups(newApiEntity.getGroups());
Proxy proxy = new Proxy();
proxy.setContextPath(newApiEntity.getContextPath());
proxy.setEndpoints(new LinkedHashSet<>());
proxy.getEndpoints().add(new HttpEndpoint("default", newApiEntity.getEndpoint()));
apiEntity.setProxy(proxy);
List<String> declaredPaths = (newApiEntity.getPaths() != null) ? newApiEntity.getPaths() : new ArrayList<>();
if (!declaredPaths.contains("/")) {
declaredPaths.add(0, "/");
}
// Initialize with a default path and provided paths
Map<String, Path> paths = declaredPaths.stream().map(sPath -> {
Path path = new Path();
path.setPath(sPath);
return path;
}).collect(Collectors.toMap(Path::getPath, path -> path));
apiEntity.setPaths(paths);
return create0(apiEntity, userId);
}
use of io.gravitee.definition.model.Proxy in project gravitee-management-rest-api by gravitee-io.
the class ApiService_UpdateTest method testUpdateWithContextPath.
private void testUpdateWithContextPath(String existingContextPath, String contextPathToCreate) throws TechnicalException {
when(apiRepository.findById(API_ID)).thenReturn(Optional.of(api));
when(apiRepository.update(any())).thenReturn(api);
when(api.getId()).thenReturn(API_ID2);
when(api.getName()).thenReturn(API_NAME);
when(existingApi.getName()).thenReturn(API_NAME);
when(existingApi.getVersion()).thenReturn("v1");
when(existingApi.getDescription()).thenReturn("Ma description");
final Proxy proxy = mock(Proxy.class);
when(existingApi.getProxy()).thenReturn(proxy);
when(proxy.getContextPath()).thenReturn(contextPathToCreate);
when(apiRepository.findAll()).thenReturn(new HashSet<>(Collections.singletonList(api)));
when(api.getDefinition()).thenReturn("{\"id\": \"" + API_ID + "\",\"name\": \"" + API_NAME + "\",\"proxy\": {\"context_path\": \"" + existingContextPath + "\"}}");
Membership po1 = new Membership("admin", API_ID, MembershipReferenceType.API);
po1.setRoles(Collections.singletonMap(RoleScope.API.getId(), SystemRole.PRIMARY_OWNER.name()));
when(membershipRepository.findByReferencesAndRole(MembershipReferenceType.API, Collections.singletonList(API_ID), RoleScope.API, SystemRole.PRIMARY_OWNER.name())).thenReturn(Collections.singleton(po1));
Membership po2 = new Membership("admin", API_ID2, MembershipReferenceType.API);
po2.setRoles(Collections.singletonMap(RoleScope.API.getId(), SystemRole.PRIMARY_OWNER.name()));
when(membershipRepository.findByReferencesAndRole(MembershipReferenceType.API, Collections.singletonList(API_ID2), RoleScope.API, SystemRole.PRIMARY_OWNER.name())).thenReturn(Collections.singleton(po2));
apiService.update(API_ID, existingApi);
}
use of io.gravitee.definition.model.Proxy in project gravitee-management-rest-api by gravitee-io.
the class ApiService_UpdateTest method shouldUpdate.
@Test
public void shouldUpdate() throws TechnicalException {
when(apiRepository.findById(API_ID)).thenReturn(Optional.of(api));
when(apiRepository.update(any())).thenReturn(api);
when(api.getName()).thenReturn(API_NAME);
when(existingApi.getName()).thenReturn(API_NAME);
when(existingApi.getVersion()).thenReturn("v1");
when(existingApi.getDescription()).thenReturn("Ma description");
final Proxy proxy = mock(Proxy.class);
when(existingApi.getProxy()).thenReturn(proxy);
when(proxy.getContextPath()).thenReturn("/context");
Membership po = new Membership(USER_NAME, API_ID, MembershipReferenceType.API);
po.setRoles(Collections.singletonMap(RoleScope.API.getId(), SystemRole.PRIMARY_OWNER.name()));
when(membershipRepository.findByReferencesAndRole(any(), any(), any(), any())).thenReturn(Collections.singleton(po));
final ApiEntity apiEntity = apiService.update(API_ID, existingApi);
assertNotNull(apiEntity);
assertEquals(API_NAME, apiEntity.getName());
}
use of io.gravitee.definition.model.Proxy in project gravitee-gateway by gravitee-io.
the class ApiPathResolverTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
final Map<String, Path> paths = new HashMap<>();
paths.putAll(new HashMap<String, Path>() {
{
Path p1 = new Path();
p1.setPath("/");
put(p1.getPath(), p1);
Path p2 = new Path();
p2.setPath("/products");
put(p2.getPath(), p2);
Path p3 = new Path();
p3.setPath("/stores");
put(p3.getPath(), p3);
Path p4 = new Path();
p4.setPath("/stores/:storeId");
put(p4.getPath(), p4);
Path p5 = new Path();
p5.setPath("/[0-9,;]+");
put(p5.getPath(), p5);
Path p6 = new Path();
p6.setPath("/Stores/:storeId");
put(p6.getPath(), p6);
}
});
// API 1
Proxy proxy = new Proxy();
proxy.setContextPath("/");
when(api.getProxy()).thenReturn(proxy);
when(api.getPaths()).thenReturn(paths);
pathResolver = new ApiPathResolverImpl(api);
// API 2
Proxy proxy2 = new Proxy();
proxy2.setContextPath("/v1/products");
when(api2.getProxy()).thenReturn(proxy2);
when(api2.getPaths()).thenReturn(paths);
pathResolver2 = new ApiPathResolverImpl(api2);
}
Aggregations