use of org.eclipse.openvsx.json.ExtensionJson in project openvsx by eclipse.
the class AdminAPITest method extensionJson.
private String extensionJson(Consumer<ExtensionJson> content) throws JsonProcessingException {
var json = new ExtensionJson();
content.accept(json);
return new ObjectMapper().writeValueAsString(json);
}
use of org.eclipse.openvsx.json.ExtensionJson in project openvsx by eclipse.
the class RegistryAPITest method extensionJson.
private String extensionJson(Consumer<ExtensionJson> content) throws JsonProcessingException {
var json = new ExtensionJson();
content.accept(json);
return new ObjectMapper().writeValueAsString(json);
}
use of org.eclipse.openvsx.json.ExtensionJson in project openvsx by eclipse.
the class AdminAPI method getExtension.
@GetMapping(path = "/admin/extension/{namespaceName}/{extensionName}", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<ExtensionJson> getExtension(@PathVariable String namespaceName, @PathVariable String extensionName) {
try {
admins.checkAdminUser();
var extension = repositories.findExtension(extensionName, namespaceName);
if (extension == null) {
var json = ExtensionJson.error("Extension not found: " + namespaceName + "." + extensionName);
return new ResponseEntity<>(json, HttpStatus.NOT_FOUND);
}
ExtensionJson json;
// Don't rely on the 'latest' relationship here because the extension might be inactive
var extVersion = getLatestVersion(extension);
if (extVersion == null) {
json = new ExtensionJson();
json.namespace = extension.getNamespace().getName();
json.name = extension.getName();
json.allVersions = Collections.emptyMap();
} else {
json = local.toExtensionVersionJson(extVersion, false);
}
json.active = extension.isActive();
return ResponseEntity.ok(json);
} catch (ErrorResultException exc) {
return exc.toResponseEntity(ExtensionJson.class);
}
}
use of org.eclipse.openvsx.json.ExtensionJson in project openvsx by eclipse.
the class AdminAPITest method testGetUserPublishInfo.
@Test
public void testGetUserPublishInfo() throws Exception {
mockAdminUser();
var versions = mockExtension(1, 0, 0);
var user = new UserData();
user.setLoginName("test");
user.setProvider("github");
Mockito.when(repositories.findUserByLoginName("github", "test")).thenReturn(user);
var token = new PersonalAccessToken();
token.setUser(user);
token.setActive(true);
Mockito.when(repositories.findAccessTokens(user)).thenReturn(Streamable.of(token));
versions.forEach(v -> v.setPublishedWith(token));
Mockito.when(repositories.findVersionsByAccessToken(token)).thenReturn(Streamable.of(versions));
mockMvc.perform(get("/admin/publisher/{provider}/{loginName}", "github", "test").with(user("admin_user").authorities(new SimpleGrantedAuthority(("ROLE_ADMIN")))).with(csrf().asHeader())).andExpect(status().isOk()).andExpect(content().json(publishInfoJson(upi -> {
upi.user = new UserJson();
upi.user.loginName = "test";
upi.activeAccessTokenNum = 1;
var ext1 = new ExtensionJson();
ext1.namespace = "foobar";
ext1.name = "baz";
ext1.version = "1";
upi.extensions = Arrays.asList(ext1);
})));
}
Aggregations