Skip to content

Commit

Permalink
Add more bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
at055612 committed Jan 28, 2025
1 parent 0827bd9 commit 8f91e3b
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 19 deletions.
6 changes: 6 additions & 0 deletions stroom-app/src/test/java/stroom/receive/TestBaseModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import stroom.cache.impl.CacheModule;
import stroom.cache.service.impl.CacheServiceModule;
import stroom.cluster.lock.mock.MockClusterLockModule;
import stroom.collection.mock.MockCollectionModule;
import stroom.core.receive.ReceiveDataModule;
import stroom.data.store.mock.MockStreamStoreModule;
Expand All @@ -11,6 +12,7 @@
import stroom.docstore.impl.memory.MemoryPersistenceModule;
import stroom.documentation.impl.DocumentationModule;
import stroom.event.logging.api.DocumentEventLog;
import stroom.explorer.impl.MockExplorerModule;
import stroom.feed.impl.FeedModule;
import stroom.legacy.impex_6_1.LegacyImpexModule;
import stroom.meta.api.AttributeMap;
Expand All @@ -21,6 +23,7 @@
import stroom.receive.rules.impl.ReceiveDataRuleSetModule;
import stroom.security.api.UserIdentity;
import stroom.security.mock.MockSecurityContextModule;
import stroom.security.mock.MockSecurityModule;
import stroom.task.impl.TaskContextModule;
import stroom.test.common.MockMetricsModule;
import stroom.util.entityevent.EntityEventBus;
Expand All @@ -44,10 +47,13 @@ protected void configure() {
install(new FeedModule());
install(new LegacyImpexModule());
install(new MemoryPersistenceModule());
install(new MockClusterLockModule());
install(new MockExplorerModule());
install(new MockMetaModule());
install(new MockMetaStatisticsModule());
install(new MockMetricsModule());
install(new MockNodeServiceModule());
install(new MockSecurityModule());
install(new MockSecurityContextModule());
install(new MockStreamStoreModule());
install(new PipelineScopeModule());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ private DocRef doCreateFeed(final String feedName,
final AttributeMap attributeMap) {

final AutoContentCreationConfig config = autoContentCreationConfigProvider.get();
final String destinationPath = config.getDestinationPath();
final String destinationPath = config.getDestinationExplorerPath();
final String accountId = Objects.requireNonNull(attributeMap.get(StandardHeaderArguments.ACCOUNT_ID));
final DocPath docPath = DocPath.fromPathString(destinationPath)
.append(accountId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class AutoContentCreationConfig
private final boolean enabled;

@JsonProperty
private final String destinationPath;
private final String destinationExplorerPath;

@JsonProperty
private final String templatesPath;
Expand All @@ -45,7 +45,7 @@ public class AutoContentCreationConfig

public AutoContentCreationConfig() {
enabled = false;
destinationPath = DocPath.fromParts(DEFAULT_DESTINATION_PATH_PART)
destinationExplorerPath = DocPath.fromParts(DEFAULT_DESTINATION_PATH_PART)
.toString();
templatesPath = DocPath.fromParts(DEFAULT_DESTINATION_PATH_PART, DEFAULT_TEMPLATES_PATH_PART)
.toString();
Expand All @@ -56,13 +56,13 @@ public AutoContentCreationConfig() {

@JsonCreator
public AutoContentCreationConfig(@JsonProperty("enabled") final boolean enabled,
@JsonProperty("destinationPath") final String destinationPath,
@JsonProperty("destinationExplorerPath") final String destinationExplorerPath,
@JsonProperty("templatesPath") final String templatesPath,
@JsonProperty("additionalGroupSuffix") final String additionalGroupSuffix,
@JsonProperty("createAsSubjectId") final String createAsSubjectId,
@JsonProperty("createAsType") final UserType createAsType) {
this.enabled = enabled;
this.destinationPath = destinationPath;
this.destinationExplorerPath = destinationExplorerPath;
this.templatesPath = templatesPath;
this.additionalGroupSuffix = additionalGroupSuffix;
this.createAsSubjectId = createAsSubjectId;
Expand All @@ -71,7 +71,7 @@ public AutoContentCreationConfig(@JsonProperty("enabled") final boolean enabled,

private AutoContentCreationConfig(Builder builder) {
this.enabled = builder.enabled;
this.destinationPath = builder.destinationPath;
this.destinationExplorerPath = builder.destinationPath;
this.templatesPath = builder.templatesPath;
this.additionalGroupSuffix = builder.additionalGroupSuffix;
this.createAsSubjectId = builder.createAsSubjectId;
Expand All @@ -92,8 +92,8 @@ public boolean isEnabled() {
"The path to a folder in the Stroom explorer tree where Stroom will auto-create " +
"content. If it doesn't exist it will be created. Content will be created in a sub-folder of this " +
"folder with a name derived from the system name of the received data.")
public String getDestinationPath() {
return destinationPath;
public String getDestinationExplorerPath() {
return destinationExplorerPath;
}

@JsonPropertyDescription(
Expand Down Expand Up @@ -129,10 +129,10 @@ public UserType getCreateAsType() {
@JsonIgnore
@ValidationMethod(message = "destinationPath must be an absolute path.")
public boolean isDestinationPathValid() {
if (destinationPath == null) {
if (destinationExplorerPath == null) {
return true;
} else {
final DocPath docPath = DocPath.fromParts(destinationPath);
final DocPath docPath = DocPath.fromParts(destinationExplorerPath);
return docPath.isAbsolute();
}
}
Expand All @@ -144,7 +144,7 @@ public static Builder builder() {
public Builder copy() {
return new Builder()
.enabled(enabled)
.destinationPath(destinationPath)
.destinationPath(destinationExplorerPath)
.templatesPath(templatesPath);
}

Expand Down
2 changes: 2 additions & 0 deletions stroom-security/stroom-security-mock/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ dependencies {
implementation project(':stroom-security:stroom-security-api')
implementation project(':stroom-security:stroom-security-impl')
implementation project(':stroom-security:stroom-security-user-api')
implementation project(':stroom-test-common')
implementation project(':stroom-util-shared')
implementation project(':stroom-util')

implementation libs.jackson_annotations
implementation libs.jakarta_servlet_api
implementation libs.guice
implementation libs.mockito_core
implementation libs.ws_rs_api
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package stroom.security.mock;

import stroom.security.api.AppPermissionService;
import stroom.security.api.DocumentPermissionService;
import stroom.security.api.UserService;
import stroom.test.common.util.guice.GuiceTestUtil;

import com.google.inject.AbstractModule;

public class MockSecurityModule extends AbstractModule {

@Override
protected void configure() {
GuiceTestUtil.buildMockBinder(binder())
.addMockBindingFor(UserService.class)
.addMockBindingFor(DocumentPermissionService.class)
.addMockBindingFor(AppPermissionService.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ public static <T> T bindMock(final Binder binder, final Class<T> classToMock) {
return mock;
}

/**
* Create a {@link MockBinderBuilder} to bind multiple interfaces to a {@link Mockito} mock.
*/
public static MockBinderBuilder buildMockBinder(final Binder binder) {
return new MockBinderBuilder(binder);
}

public static String dumpGuiceModuleHierarchy(final com.google.inject.Module... modules) {
final Map<String, ModuleInfo> allModuleInfoMap = buildModuleInfoMap(modules);

Expand Down Expand Up @@ -129,7 +136,7 @@ private static Optional<BindInfo> addBindInfo(final Map<String, ModuleInfo> allM
}

if (!moduleClassNames.isEmpty()
&& moduleClassNames.get(0).startsWith("stroom.")) {
&& moduleClassNames.get(0).startsWith("stroom.")) {

final String bindingInfo = determineBindInfo(key, binding, bindingClass);
if (bindingInfo != null) {
Expand Down Expand Up @@ -161,18 +168,18 @@ private static BindType determineBindType(final Key<?> key,
final Annotation annotation = key.getAnnotation();

if (annotation != null
&& annotation.toString().contains("@com.google.inject.internal.Element")
&& annotation.toString().contains("MAPBINDER")) {
&& annotation.toString().contains("@com.google.inject.internal.Element")
&& annotation.toString().contains("MAPBINDER")) {
return BindType.MAP_BINDER;
} else if (annotation != null
&& annotation.toString().contains("@com.google.inject.internal.Element")
&& annotation.toString().contains("MULTIBINDER")) {
&& annotation.toString().contains("@com.google.inject.internal.Element")
&& annotation.toString().contains("MULTIBINDER")) {
return BindType.MULTI_BINDER;
} else {
if (InstanceBinding.class.isAssignableFrom(bindingClass)) {
return BindType.INSTANCE;
} else if (ProviderInstanceBinding.class.isAssignableFrom(bindingClass)
|| ProviderKeyBinding.class.isAssignableFrom(bindingClass)) {
|| ProviderKeyBinding.class.isAssignableFrom(bindingClass)) {
return BindType.PROVIDER;
} else {
return BindType.IMPL;
Expand Down Expand Up @@ -204,7 +211,7 @@ private static String determineBindInfo(final Key<?> key,
providerInstanceBinding,
ProviderInstanceBinding::getSource,
Object::toString)
+ ")";
+ ")";
} else if (ProviderKeyBinding.class.isAssignableFrom(bindingClass)) {
final ProviderKeyBinding<?> providerInstanceBinding =
(ProviderKeyBinding<?>) binding;
Expand All @@ -214,7 +221,7 @@ private static String determineBindInfo(final Key<?> key,
Key::getTypeLiteral,
TypeLiteral::getRawType,
Class::getName)
+ ")";
+ ")";
} else if (LinkedKeyBinding.class.isAssignableFrom(bindingClass)) {
// Standard binding of iface to impl
final LinkedKeyBinding<?> linkedKeyBinding = (LinkedKeyBinding<?>) binding;
Expand Down Expand Up @@ -453,4 +460,23 @@ public String toString() {
provider);
}
}


// --------------------------------------------------------------------------------


public static class MockBinderBuilder {

private final Binder binder;

private MockBinderBuilder(final Binder binder) {
this.binder = binder;
}

public <T> MockBinderBuilder addMockBindingFor(final Class<T> interfaceType) {
final T mock = Mockito.mock(interfaceType);
binder.bind(interfaceType).toInstance(mock);
return this;
}
}
}

0 comments on commit 8f91e3b

Please sign in to comment.