### Question:
RestBackendImpl implements RestBackend { @Override public void performDomainAction(String domainUid, DomainAction params) { verifyDomain(domainUid); authorize(domainUid, Operation.update); switch (Optional.ofNullable(params.getAction()).orElse(DomainActionType.UNKNOWN)) { case INTROSPECT: introspect(domainUid); break; case RESTART: restartDomain(domainUid); break; default: throw new WebApplicationException(Status.BAD_REQUEST); } } RestBackendImpl(String principal, String accessToken, Collection<String> targetNamespaces); @Override Set<String> getDomainUids(); @Override boolean isDomainUid(String domainUid); @Override void performDomainAction(String domainUid, DomainAction params); @Override Set<String> getClusters(String domainUid); @Override boolean isCluster(String domainUid, String cluster); @Override void scaleCluster(String domainUid, String cluster, int managedServerCount); static final String INITIAL_VERSION; }### Answer:
@Test(expected = WebApplicationException.class) public void whenUnknownDomain_throwException() { restBackend.performDomainAction("no_such_uid", new DomainAction(DomainActionType.INTROSPECT)); }
@Test(expected = WebApplicationException.class) public void whenUnknownDomainUpdateCommand_throwException() { restBackend.performDomainAction(NAME1, new DomainAction(null)); }
@Test public void whenIntrospectionRequestedWhileNoIntrospectVersionDefined_setIntrospectVersion() { restBackend.performDomainAction(NAME1, createIntrospectRequest()); assertThat(getUpdatedIntrospectVersion(), equalTo(INITIAL_VERSION)); }
@Test public void whenIntrospectionRequestedWhileIntrospectVersionNonNumeric_setNumericVersion() { configurator.withIntrospectVersion("zork"); restBackend.performDomainAction(NAME1, createIntrospectRequest()); assertThat(getUpdatedIntrospectVersion(), equalTo(INITIAL_VERSION)); }
@Test public void whenIntrospectionRequestedWhileIntrospectVersionDefined_incrementIntrospectVersion() { configurator.withIntrospectVersion("17"); restBackend.performDomainAction(NAME1, createIntrospectRequest()); assertThat(getUpdatedIntrospectVersion(), equalTo("18")); }
@Test public void whenClusterRestartRequestedWhileNoRestartVersionDefined_setRestartVersion() { restBackend.performDomainAction(NAME1, createDomainRestartRequest()); assertThat(getUpdatedRestartVersion(), equalTo(INITIAL_VERSION)); }
@Test public void whenRestartRequestedWhileRestartVersionDefined_incrementIntrospectVersion() { configurator.withRestartVersion("23"); restBackend.performDomainAction(NAME1, createDomainRestartRequest()); assertThat(getUpdatedRestartVersion(), equalTo("24")); }
@Test public void whenDomainRestartRequestedWhileNoRestartVersionDefined_setRestartVersion() { restBackend.performDomainAction(NAME1, createDomainRestartRequest()); assertThat(getUpdatedRestartVersion(), equalTo(INITIAL_VERSION)); }