Skip to content

Commit

Permalink
Added Docs, Write-Permission & Unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrill-nt committed Jul 6, 2020
1 parent e2152a4 commit 738d7c6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import rocks.inspectit.ocelot.file.FileChangedEvent;
Expand All @@ -14,9 +15,13 @@
import rocks.inspectit.ocelot.agentconfiguration.AgentConfiguration;
import rocks.inspectit.ocelot.agentconfiguration.AgentConfigurationManager;
import rocks.inspectit.ocelot.config.model.InspectitConfig;
import rocks.inspectit.ocelot.security.config.UserRoleConfiguration;

import java.util.Map;

/**
* Controller for endpoints related to configuration files.
*/
@RestController
public class ConfigurationController extends AbstractBaseController {

Expand All @@ -40,6 +45,7 @@ private void fireFileChangeEvent() {
/**
* Reloads all configuration files present in the servers working directory.
*/
@Secured(UserRoleConfiguration.WRITE_ACCESS_ROLE)
@ApiOperation(value = "Reloads all configuration files.", notes = "Reloads all configuration files present in the " +
"servers working directory.")
@GetMapping(value = "configuration/reload", produces = "text/plain")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.springframework.context.ApplicationEventPublisher;
import rocks.inspectit.ocelot.file.FileChangedEvent;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;

@ExtendWith(MockitoExtension.class)
public class ConfigurationControllerTest {
Expand All @@ -31,6 +36,9 @@ public class ConfigurationControllerTest {
@Mock
AgentConfigurationManager agentConfigurationManager;

@Mock
ApplicationEventPublisher applicationEventPublisher;

@Nested
public class FetchConfiguration {

Expand All @@ -54,4 +62,15 @@ public void noConfigurationAvailable() {
assertThat(output.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
}
}

@Nested
public class ReloadConfiguration {

@Test
public void firesFileChangedEvent() {
configurationController.reloadConfiguration();

verify(applicationEventPublisher).publishEvent(any(FileChangedEvent.class));
}
}
}

0 comments on commit 738d7c6

Please sign in to comment.