From 315efdac765fb6cec8fd099b2b157683dbf8a493 Mon Sep 17 00:00:00 2001 From: raoulvdberge Date: Wed, 8 May 2024 17:12:28 +0200 Subject: [PATCH] refactor: relay in api layer - storage --- .../core/component/ComponentMapFactory.java | 6 +- ...ava => InjectNetworkStorageComponent.java} | 2 +- .../network/test/NetworkTestExtension.java | 9 +- .../network/test/NetworkTestFixtures.java | 2 +- .../test/{util => fake}/FakeActor.java | 2 +- .../test/{util => fake}/FakePermissions.java | 2 +- .../FakeResources.java} | 4 +- .../{util => fake}/FakeSecurityActors.java | 2 +- .../test/{util => fake}/package-info.java | 2 +- .../test/NetworkTestExtensionTest.java | 11 +- .../node/relay/RelayInputNetworkNode.java | 47 ++ .../node/relay/RelayOutputNetworkNode.java | 49 +- .../impl/node/relay/RelayOutputStorage.java | 186 ++--- .../impl/PriorityNetworkBuilderImplTest.java | 2 +- .../detector/DetectorNetworkNodeTest.java | 14 +- .../AbstractExporterNetworkNodeTest.java | 108 +-- ...FirstAvailableExporterNetworkNodeTest.java | 48 +- .../RandomExporterNetworkNodeTest.java | 30 +- .../RoundRobinExporterNetworkNodeTest.java | 66 +- .../ExternalStorageNetworkNodeTest.java | 73 +- .../impl/node/grid/GridNetworkNodeTest.java | 36 +- .../ClearSlotInterfaceNetworkNodeTest.java | 36 +- ...rtToEmptySlotInterfaceNetworkNodeTest.java | 52 +- .../node/iface/InterfaceExportStateImpl.java | 6 +- .../node/iface/InterfaceNetworkNodeTest.java | 38 +- ...KeepExportingInterfaceNetworkNodeTest.java | 112 ++-- ...erfaceExternalStorageProviderImplTest.java | 58 +- ...erfaceExternalStorageProviderImplTest.java | 16 +- ...erfaceExternalStorageProviderImplTest.java | 8 +- .../importer/ImporterNetworkNodeTest.java | 110 +-- .../MultiStorageNetworkNodeTest.java | 66 +- .../PriorityMultiStorageNetworkNodeTest.java | 8 +- .../relay/RelayEnergyNetworkNodeTest.java | 106 +++ .../impl/node/relay/RelayNetworkNodeTest.java | 378 ++++++----- .../relay/RelaySecurityNetworkNodeTest.java | 165 +++++ .../relay/RelayStorageNetworkNodeTest.java | 634 ++++++++++++++++++ .../node/storage/StorageNetworkNodeTest.java | 57 +- .../SecurityNetworkComponentImplTest.java | 4 +- .../StorageNetworkComponentImplTest.java | 4 +- .../common/AbstractModInitializer.java | 6 + .../common/networking/RelayBlockEntity.java | 138 ++-- .../common/networking/RelayContainerMenu.java | 6 + ...va => RelayInputNetworkNodeContainer.java} | 8 +- .../networking/RelayMainNetworkNode.java | 108 --- .../networking/RelayOuterNetworkNode.java | 136 ---- ...a => RelayOutputNetworkNodeContainer.java} | 17 +- .../common/networking/RelayScreen.java | 21 + .../assets/refinedstorage2/lang/en_us.json | 2 +- .../api/storage/channel/StorageChannel.java | 2 +- .../storage/composite/PriorityStorage.java} | 12 +- .../channel/StorageChannelImplTest.java | 8 +- .../composite/CompositeStorageImplTest.java | 16 +- .../ExtractCompositeStorageImplTest.java | 4 +- .../InsertCompositeStorageImplTest.java | 4 +- 54 files changed, 1947 insertions(+), 1100 deletions(-) rename refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/{InjectNetworkStorageChannel.java => InjectNetworkStorageComponent.java} (86%) rename refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/{util => fake}/FakeActor.java (82%) rename refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/{util => fake}/FakePermissions.java (73%) rename refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/{TestResource.java => fake/FakeResources.java} (58%) rename refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/{util => fake}/FakeSecurityActors.java (71%) rename refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/{util => fake}/package-info.java (78%) rename refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayOuterNetworkNodeStorage.java => refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/relay/RelayOutputStorage.java (54%) create mode 100644 refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/relay/RelayEnergyNetworkNodeTest.java create mode 100644 refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/relay/RelaySecurityNetworkNodeTest.java create mode 100644 refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/relay/RelayStorageNetworkNodeTest.java rename refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/{RelayMainNetworkNodeContainer.java => RelayInputNetworkNodeContainer.java} (80%) delete mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayMainNetworkNode.java delete mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayOuterNetworkNode.java rename refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/{RelayOuterNetworkNodeContainer.java => RelayOutputNetworkNodeContainer.java} (58%) rename refinedstorage2-storage-api/src/{test/java/com/refinedmods/refinedstorage2/api/storage/composite/PrioritizedStorage.java => main/java/com/refinedmods/refinedstorage2/api/storage/composite/PriorityStorage.java} (53%) diff --git a/refinedstorage2-core-api/src/main/java/com/refinedmods/refinedstorage2/api/core/component/ComponentMapFactory.java b/refinedstorage2-core-api/src/main/java/com/refinedmods/refinedstorage2/api/core/component/ComponentMapFactory.java index e69e7880d..370f57cf1 100644 --- a/refinedstorage2-core-api/src/main/java/com/refinedmods/refinedstorage2/api/core/component/ComponentMapFactory.java +++ b/refinedstorage2-core-api/src/main/java/com/refinedmods/refinedstorage2/api/core/component/ComponentMapFactory.java @@ -26,9 +26,13 @@ public ComponentMapFactory copy() { return new ComponentMapFactory<>(new LinkedHashMap<>(factories)); } + @SuppressWarnings("unchecked") public ComponentMap buildComponentMap(final X context) { final Map, C> components = new LinkedHashMap<>(); - factories.forEach((componentType, factory) -> components.put(componentType, factory.apply(context))); + factories.forEach((componentType, factory) -> { + final C component = factory.apply(context); + components.put(componentType, component); + }); return new ComponentMap<>(components); } } diff --git a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/InjectNetworkStorageChannel.java b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/InjectNetworkStorageComponent.java similarity index 86% rename from refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/InjectNetworkStorageChannel.java rename to refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/InjectNetworkStorageComponent.java index 58b66a386..a78bd1f77 100644 --- a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/InjectNetworkStorageChannel.java +++ b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/InjectNetworkStorageComponent.java @@ -7,6 +7,6 @@ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.PARAMETER) -public @interface InjectNetworkStorageChannel { +public @interface InjectNetworkStorageComponent { String networkId() default "default"; } diff --git a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/NetworkTestExtension.java b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/NetworkTestExtension.java index 8b6027d53..dbcb0be5a 100644 --- a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/NetworkTestExtension.java +++ b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/NetworkTestExtension.java @@ -10,7 +10,6 @@ import com.refinedmods.refinedstorage2.api.network.node.NetworkNode; import com.refinedmods.refinedstorage2.api.network.security.SecurityNetworkComponent; import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.network.test.nodefactory.NetworkNodeFactory; import java.lang.annotation.Annotation; @@ -192,7 +191,7 @@ private void setField(final Object instance, final Field field, final Object val @Override public boolean supportsParameter(final ParameterContext parameterContext, final ExtensionContext extensionContext) throws ParameterResolutionException { - return parameterContext.isAnnotated(InjectNetworkStorageChannel.class) + return parameterContext.isAnnotated(InjectNetworkStorageComponent.class) || parameterContext.isAnnotated(InjectNetworkEnergyComponent.class) || parameterContext.isAnnotated(InjectNetworkSecurityComponent.class) || parameterContext.isAnnotated(InjectNetwork.class); @@ -202,8 +201,8 @@ public boolean supportsParameter(final ParameterContext parameterContext, public Object resolveParameter(final ParameterContext parameterContext, final ExtensionContext extensionContext) throws ParameterResolutionException { return parameterContext - .findAnnotation(InjectNetworkStorageChannel.class) - .map(annotation -> (Object) getNetworkStorageChannel(annotation.networkId())) + .findAnnotation(InjectNetworkStorageComponent.class) + .map(annotation -> (Object) getNetworkStorage(annotation.networkId())) .or(() -> parameterContext .findAnnotation(InjectNetworkEnergyComponent.class) .map(annotation -> (Object) getNetworkEnergy(annotation.networkId()))) @@ -216,7 +215,7 @@ public Object resolveParameter(final ParameterContext parameterContext, .orElseThrow(); } - private StorageChannel getNetworkStorageChannel(final String networkId) { + private StorageNetworkComponent getNetworkStorage(final String networkId) { return networkMap.get(networkId).getComponent(StorageNetworkComponent.class); } diff --git a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/NetworkTestFixtures.java b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/NetworkTestFixtures.java index f39cf66e0..4cbfc678c 100644 --- a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/NetworkTestFixtures.java +++ b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/NetworkTestFixtures.java @@ -13,7 +13,7 @@ import com.refinedmods.refinedstorage2.api.network.security.SecurityPolicy; import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.resource.list.ResourceListImpl; -import com.refinedmods.refinedstorage2.network.test.util.FakePermissions; +import com.refinedmods.refinedstorage2.network.test.fake.FakePermissions; public final class NetworkTestFixtures { public static final ComponentMapFactory NETWORK_COMPONENT_MAP_FACTORY = diff --git a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/util/FakeActor.java b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/fake/FakeActor.java similarity index 82% rename from refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/util/FakeActor.java rename to refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/fake/FakeActor.java index 27f1d6963..c746b2e03 100644 --- a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/util/FakeActor.java +++ b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/fake/FakeActor.java @@ -1,4 +1,4 @@ -package com.refinedmods.refinedstorage2.network.test.util; +package com.refinedmods.refinedstorage2.network.test.fake; import com.refinedmods.refinedstorage2.api.storage.Actor; diff --git a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/util/FakePermissions.java b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/fake/FakePermissions.java similarity index 73% rename from refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/util/FakePermissions.java rename to refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/fake/FakePermissions.java index 497f906b1..8e8e42914 100644 --- a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/util/FakePermissions.java +++ b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/fake/FakePermissions.java @@ -1,4 +1,4 @@ -package com.refinedmods.refinedstorage2.network.test.util; +package com.refinedmods.refinedstorage2.network.test.fake; import com.refinedmods.refinedstorage2.api.network.security.Permission; diff --git a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/TestResource.java b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/fake/FakeResources.java similarity index 58% rename from refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/TestResource.java rename to refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/fake/FakeResources.java index d5fa8fd57..3a3f9faca 100644 --- a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/TestResource.java +++ b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/fake/FakeResources.java @@ -1,8 +1,8 @@ -package com.refinedmods.refinedstorage2.network.test; +package com.refinedmods.refinedstorage2.network.test.fake; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; -public enum TestResource implements ResourceKey { +public enum FakeResources implements ResourceKey { A, A_ALTERNATIVE, A_ALTERNATIVE2, diff --git a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/util/FakeSecurityActors.java b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/fake/FakeSecurityActors.java similarity index 71% rename from refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/util/FakeSecurityActors.java rename to refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/fake/FakeSecurityActors.java index 2223ec3e0..c0852bf24 100644 --- a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/util/FakeSecurityActors.java +++ b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/fake/FakeSecurityActors.java @@ -1,4 +1,4 @@ -package com.refinedmods.refinedstorage2.network.test.util; +package com.refinedmods.refinedstorage2.network.test.fake; import com.refinedmods.refinedstorage2.api.network.security.SecurityActor; diff --git a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/util/package-info.java b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/fake/package-info.java similarity index 78% rename from refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/util/package-info.java rename to refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/fake/package-info.java index a2f32aa2c..c0900bc54 100644 --- a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/util/package-info.java +++ b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/fake/package-info.java @@ -1,6 +1,6 @@ @ParametersAreNonnullByDefault @FieldsAndMethodsAreNonnullByDefault -package com.refinedmods.refinedstorage2.network.test.util; +package com.refinedmods.refinedstorage2.network.test.fake; import com.refinedmods.refinedstorage2.api.core.FieldsAndMethodsAreNonnullByDefault; diff --git a/refinedstorage2-network-test/src/test/java/com/refinedmods/refinedstorage2/network/test/NetworkTestExtensionTest.java b/refinedstorage2-network-test/src/test/java/com/refinedmods/refinedstorage2/network/test/NetworkTestExtensionTest.java index e7c9e880d..647940cc9 100644 --- a/refinedstorage2-network-test/src/test/java/com/refinedmods/refinedstorage2/network/test/NetworkTestExtensionTest.java +++ b/refinedstorage2-network-test/src/test/java/com/refinedmods/refinedstorage2/network/test/NetworkTestExtensionTest.java @@ -9,7 +9,6 @@ import com.refinedmods.refinedstorage2.api.network.node.container.NetworkNodeContainer; import com.refinedmods.refinedstorage2.api.network.security.SecurityNetworkComponent; import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.network.test.nodefactory.AbstractNetworkNodeFactory; import com.refinedmods.refinedstorage2.network.test.nodefactory.MultiStorageNetworkNodeFactory; import com.refinedmods.refinedstorage2.network.test.nodefactory.SimpleNetworkNodeFactory; @@ -129,13 +128,13 @@ void shouldAddNetworkNodeToGraph() { } @Test - void shouldInjectStorageChannel( - @InjectNetworkStorageChannel(networkId = "a") final StorageChannel storageChannelA, - @InjectNetworkStorageChannel(networkId = "b") final StorageChannel storageChannelB + void shouldInjectNetworkStorageComponent( + @InjectNetworkStorageComponent(networkId = "a") final StorageNetworkComponent networkStorageA, + @InjectNetworkStorageComponent(networkId = "b") final StorageNetworkComponent networkStorageB ) { // Assert - assertThat(storageChannelA).isSameAs(a.getComponent(StorageNetworkComponent.class)); - assertThat(storageChannelB).isSameAs(b.getComponent(StorageNetworkComponent.class)); + assertThat(networkStorageA).isSameAs(a.getComponent(StorageNetworkComponent.class)); + assertThat(networkStorageB).isSameAs(b.getComponent(StorageNetworkComponent.class)); } @Test diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/relay/RelayInputNetworkNode.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/relay/RelayInputNetworkNode.java index dc59c73d1..955f7c097 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/relay/RelayInputNetworkNode.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/relay/RelayInputNetworkNode.java @@ -5,9 +5,13 @@ import com.refinedmods.refinedstorage2.api.network.impl.node.AbstractNetworkNode; import com.refinedmods.refinedstorage2.api.network.security.SecurityNetworkComponent; import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; +import com.refinedmods.refinedstorage2.api.resource.ResourceKey; +import com.refinedmods.refinedstorage2.api.resource.filter.FilterMode; +import com.refinedmods.refinedstorage2.api.storage.AccessMode; import java.util.HashSet; import java.util.Set; +import java.util.function.UnaryOperator; import javax.annotation.Nullable; public class RelayInputNetworkNode extends AbstractNetworkNode { @@ -43,6 +47,15 @@ public void setComponentTypes(final Set componentTypes) { updateComponents(); } + public void updateComponentType(final RelayComponentType componentType, final boolean enabled) { + if (enabled) { + componentTypes.add(componentType); + } else { + componentTypes.remove(componentType); + } + updateComponents(); + } + private void updateComponents() { if (outputNode == null) { return; @@ -62,6 +75,40 @@ private void updateComponents() { : null); } + public void setAccessMode(final AccessMode accessMode) { + if (outputNode != null) { + outputNode.setAccessMode(accessMode); + } + } + + public void setPriority(final int priority) { + if (outputNode != null) { + outputNode.setPriority(priority); + } + } + + public void setFilters(final Set filters) { + if (outputNode != null) { + outputNode.setFilters(filters); + } + } + + public void setFilterMode(final FilterMode filterMode) { + if (outputNode != null) { + outputNode.setFilterMode(filterMode); + } + } + + public void setFilterNormalizer(final UnaryOperator normalizer) { + if (outputNode != null) { + outputNode.setFilterNormalizer(normalizer); + } + } + + public boolean hasComponentType(final RelayComponentType componentType) { + return componentTypes.contains(componentType); + } + @Override public long getEnergyUsage() { return energyUsage; diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/relay/RelayOutputNetworkNode.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/relay/RelayOutputNetworkNode.java index c8be56611..2abe51359 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/relay/RelayOutputNetworkNode.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/relay/RelayOutputNetworkNode.java @@ -9,19 +9,25 @@ import com.refinedmods.refinedstorage2.api.network.security.SecurityDecisionProvider; import com.refinedmods.refinedstorage2.api.network.security.SecurityNetworkComponent; import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; - +import com.refinedmods.refinedstorage2.api.network.storage.StorageProvider; +import com.refinedmods.refinedstorage2.api.resource.ResourceKey; +import com.refinedmods.refinedstorage2.api.resource.filter.FilterMode; +import com.refinedmods.refinedstorage2.api.storage.AccessMode; +import com.refinedmods.refinedstorage2.api.storage.Storage; + +import java.util.Set; +import java.util.function.UnaryOperator; import javax.annotation.Nullable; public class RelayOutputNetworkNode extends AbstractNetworkNode - implements EnergyProvider, SecurityDecisionProvider { + implements EnergyProvider, SecurityDecisionProvider, StorageProvider { private final long energyUsage; + private final RelayOutputStorage storage = new RelayOutputStorage(); @Nullable private EnergyNetworkComponent energyDelegate; @Nullable private SecurityNetworkComponent securityDelegate; - @Nullable - private StorageNetworkComponent storageDelegate; public RelayOutputNetworkNode(final long energyUsage) { this.energyUsage = energyUsage; @@ -36,12 +42,38 @@ void setSecurityDelegate(@Nullable final SecurityNetworkComponent securityDelega } void setStorageDelegate(@Nullable final StorageNetworkComponent storageDelegate) { - this.storageDelegate = storageDelegate; + this.storage.setDelegate(storageDelegate); + } + + void setAccessMode(final AccessMode accessMode) { + this.storage.setAccessMode(accessMode); + } + + void setPriority(final int priority) { + this.storage.setPriority(priority); + if (network != null) { + network.getComponent(StorageNetworkComponent.class).sortSources(); + } + } + + void setFilters(final Set filters) { + this.storage.setFilters(filters); + } + + void setFilterMode(final FilterMode filterMode) { + this.storage.setFilterMode(filterMode); + } + + void setFilterNormalizer(final UnaryOperator normalizer) { + this.storage.setFilterNormalizer(normalizer); } @Override public long getEnergyUsage() { - return energyUsage; + if (energyDelegate != null || securityDelegate != null || storage.hasDelegate()) { + return energyUsage; + } + return 0; } @Override @@ -83,4 +115,9 @@ public SecurityDecision isAllowed(final Permission permission, final SecurityAct public boolean isProviderActive() { return isActive() && securityDelegate != null; } + + @Override + public Storage getStorage() { + return storage; + } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayOuterNetworkNodeStorage.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/relay/RelayOutputStorage.java similarity index 54% rename from refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayOuterNetworkNodeStorage.java rename to refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/relay/RelayOutputStorage.java index ab5dd9bc4..c0693fb68 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayOuterNetworkNodeStorage.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/relay/RelayOutputStorage.java @@ -1,4 +1,4 @@ -package com.refinedmods.refinedstorage2.platform.common.networking; +package com.refinedmods.refinedstorage2.api.network.impl.node.relay; import com.refinedmods.refinedstorage2.api.core.Action; import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; @@ -19,53 +19,20 @@ import java.util.Collections; import java.util.HashSet; import java.util.Set; +import java.util.function.UnaryOperator; import javax.annotation.Nullable; -class RelayOuterNetworkNodeStorage implements CompositeAwareChild, ResourceListListener, Priority { - private final Set outerParentComposites = new HashSet<>(); +class RelayOutputStorage implements CompositeAwareChild, ResourceListListener, Priority { + private final Set parentComposites = new HashSet<>(); private final Filter filter = new Filter(); + + @Nullable + private StorageNetworkComponent delegate; private AccessMode accessMode = AccessMode.INSERT_EXTRACT; private int priority; - @Nullable - private StorageNetworkComponent mainStorageChannel; - - boolean isActive() { - return mainStorageChannel != null; - } - void resetMainStorageChannel(final Runnable action) { - final StorageNetworkComponent storageChannel = mainStorageChannel; - setMainStorageChannel(null); - action.run(); - setMainStorageChannel(storageChannel); - } - - void setMainStorageChannel(@Nullable final StorageNetworkComponent mainStorageChannel) { - if (this.mainStorageChannel != null) { - outerParentComposites.forEach(outerParentComposite -> - getAll().forEach(resourceAmount -> outerParentComposite.removeFromCache( - resourceAmount.getResource(), - resourceAmount.getAmount() - ))); - this.mainStorageChannel.removeListener(this); - } - this.mainStorageChannel = mainStorageChannel; - if (mainStorageChannel != null) { - outerParentComposites.forEach(outerParentComposite -> - getAll().forEach(resourceAmount -> outerParentComposite.addToCache( - resourceAmount.getResource(), - resourceAmount.getAmount() - ))); - mainStorageChannel.addListener(this); - } - } - - void setFilterMode(final FilterMode filterMode) { - filter.setMode(filterMode); - } - - void setFilters(final Set filters) { - filter.setFilters(filters); + boolean hasDelegate() { + return delegate != null; } void setAccessMode(final AccessMode accessMode) { @@ -76,47 +43,56 @@ void setPriority(final int priority) { this.priority = priority; } - @Override - public long extract(final ResourceKey resource, final long amount, final Action action, final Actor actor) { - throw new UnsupportedOperationException(); + void setFilters(final Set filters) { + reset(() -> filter.setFilters(filters)); } - @Override - public long insert(final ResourceKey resource, final long amount, final Action action, final Actor actor) { - throw new UnsupportedOperationException(); + void setFilterMode(final FilterMode filterMode) { + reset(() -> filter.setMode(filterMode)); } - @Override - public Collection getAll() { - if (mainStorageChannel == null) { - return Collections.emptyList(); - } - return mainStorageChannel.getAll() - .stream() - .filter(resourceAmount -> filter.isAllowed(resourceAmount.getResource())) - .toList(); + void setFilterNormalizer(final UnaryOperator normalizer) { + reset(() -> filter.setNormalizer(normalizer)); } - @Override - public long getStored() { - if (mainStorageChannel == null) { - return 0; + private void reset(final Runnable action) { + final StorageNetworkComponent oldDelegate = delegate; + setDelegate(null); + action.run(); + setDelegate(oldDelegate); + } + + void setDelegate(@Nullable final StorageNetworkComponent delegate) { + if (this.delegate != null) { + parentComposites.forEach(parent -> getAll().forEach(resourceAmount -> parent.removeFromCache( + resourceAmount.getResource(), + resourceAmount.getAmount() + ))); + this.delegate.removeListener(this); + } + this.delegate = delegate; + if (delegate != null) { + parentComposites.forEach(parent -> getAll().forEach(resourceAmount -> parent.addToCache( + resourceAmount.getResource(), + resourceAmount.getAmount() + ))); + delegate.addListener(this); } - return mainStorageChannel.getAll() - .stream() - .filter(resourceAmount -> filter.isAllowed(resourceAmount.getResource())) - .mapToLong(ResourceAmount::getAmount) - .sum(); } @Override public void onAddedIntoComposite(final ParentComposite parentComposite) { - outerParentComposites.add(parentComposite); + parentComposites.add(parentComposite); } @Override public void onRemovedFromComposite(final ParentComposite parentComposite) { - outerParentComposites.remove(parentComposite); + parentComposites.remove(parentComposite); + } + + @Override + public boolean contains(final Storage storage) { + return storage == delegate || (delegate != null && delegate.contains(storage)); } @Override @@ -124,13 +100,13 @@ public Amount compositeInsert(final ResourceKey resource, final long amount, final Action action, final Actor actor) { - if (mainStorageChannel == null - || !filter.isAllowed(resource) - || mainStorageChannel.contains(mainStorageChannel) - || accessMode == AccessMode.EXTRACT) { + if (delegate == null + || accessMode == AccessMode.EXTRACT + || delegate.contains(delegate) + || !filter.isAllowed(resource)) { return Amount.ZERO; } - final long inserted = mainStorageChannel.insert(resource, amount, action, actor); + final long inserted = delegate.insert(resource, amount, action, actor); return new Amount(inserted, 0); } @@ -139,37 +115,63 @@ public Amount compositeExtract(final ResourceKey resource, final long amount, final Action action, final Actor actor) { - if (mainStorageChannel == null - || !filter.isAllowed(resource) - || mainStorageChannel.contains(mainStorageChannel) - || accessMode == AccessMode.INSERT) { + if (delegate == null + || accessMode == AccessMode.INSERT + || delegate.contains(delegate) + || !filter.isAllowed(resource)) { return Amount.ZERO; } - final long extracted = mainStorageChannel.extract(resource, amount, action, actor); + final long extracted = delegate.extract(resource, amount, action, actor); return new Amount(extracted, 0); } @Override - public boolean contains(final Storage storage) { - return storage == mainStorageChannel || (mainStorageChannel != null && mainStorageChannel.contains(storage)); + public long extract(final ResourceKey resource, final long amount, final Action action, final Actor actor) { + throw new UnsupportedOperationException(); + } + + @Override + public long insert(final ResourceKey resource, final long amount, final Action action, final Actor actor) { + throw new UnsupportedOperationException(); + } + + @Override + public Collection getAll() { + if (delegate == null || delegate.contains(delegate)) { + return Collections.emptyList(); + } + return delegate.getAll() + .stream() + .filter(resourceAmount -> filter.isAllowed(resourceAmount.getResource())) + .toList(); + } + + @Override + public long getStored() { + if (delegate == null || delegate.contains(delegate)) { + return 0; + } + return delegate.getAll() + .stream() + .filter(resourceAmount -> filter.isAllowed(resourceAmount.getResource())) + .mapToLong(ResourceAmount::getAmount) + .sum(); } @Override public void onChanged(final ResourceList.OperationResult change) { - if (mainStorageChannel != null && mainStorageChannel.contains(mainStorageChannel)) { + if (delegate != null && delegate.contains(delegate)) { + return; + } + final ResourceKey resource = change.resourceAmount().getResource(); + if (!filter.isAllowed(resource)) { return; } - outerParentComposites.forEach(outerParentComposite -> { - final ResourceKey resource = change.resourceAmount().getResource(); - if (!filter.isAllowed(resource)) { - return; - } - if (change.change() > 0) { - outerParentComposite.addToCache(resource, change.change()); - } else if (change.change() < 0) { - outerParentComposite.removeFromCache(resource, Math.abs(change.change())); - } - }); + if (change.change() > 0) { + parentComposites.forEach(parent -> parent.addToCache(resource, change.change())); + } else { + parentComposites.forEach(parent -> parent.removeFromCache(resource, -change.change())); + } } @Override diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/PriorityNetworkBuilderImplTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/PriorityNetworkBuilderImplTest.java index b6fb80561..b5b5bea44 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/PriorityNetworkBuilderImplTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/PriorityNetworkBuilderImplTest.java @@ -11,7 +11,7 @@ import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.api.storage.EmptyActor; import com.refinedmods.refinedstorage2.api.storage.InMemoryStorageImpl; -import com.refinedmods.refinedstorage2.network.test.util.FakeActor; +import com.refinedmods.refinedstorage2.network.test.fake.FakeActor; import java.util.function.Supplier; diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/detector/DetectorNetworkNodeTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/detector/DetectorNetworkNodeTest.java index 936654442..d22d2903b 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/detector/DetectorNetworkNodeTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/detector/DetectorNetworkNodeTest.java @@ -1,11 +1,11 @@ package com.refinedmods.refinedstorage2.api.network.impl.node.detector; import com.refinedmods.refinedstorage2.api.core.Action; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.storage.EmptyActor; import com.refinedmods.refinedstorage2.api.storage.InMemoryStorageImpl; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; -import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageChannel; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageComponent; import com.refinedmods.refinedstorage2.network.test.NetworkTest; import com.refinedmods.refinedstorage2.network.test.SetupNetwork; import com.refinedmods.refinedstorage2.network.test.nodefactory.AbstractNetworkNodeFactory; @@ -19,7 +19,7 @@ import org.junit.jupiter.params.provider.EnumSource; import org.junit.jupiter.params.provider.MethodSource; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A; import static org.assertj.core.api.Assertions.assertThat; @NetworkTest @@ -33,8 +33,8 @@ class DetectorNetworkNodeTest { DetectorNetworkNode sut; @BeforeEach - void setUp(@InjectNetworkStorageChannel final StorageChannel storageChannel) { - storageChannel.addSource(new InMemoryStorageImpl()); + void setUp(@InjectNetworkStorageComponent final StorageNetworkComponent storage) { + storage.addSource(new InMemoryStorageImpl()); sut.setAmountStrategy(new DetectorAmountStrategyImpl()); } @@ -118,14 +118,14 @@ void testModes(final DetectorMode mode, final long comparisonAmount, final long amountInNetwork, final boolean expectedActivated, - @InjectNetworkStorageChannel final StorageChannel storageChannel) { + @InjectNetworkStorageComponent final StorageNetworkComponent storage) { // Arrange sut.setConfiguredResource(A); sut.setMode(mode); sut.setAmount(comparisonAmount); if (amountInNetwork > 0) { - storageChannel.insert(A, amountInNetwork, Action.EXECUTE, EmptyActor.INSTANCE); + storage.insert(A, amountInNetwork, Action.EXECUTE, EmptyActor.INSTANCE); } // Act diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/AbstractExporterNetworkNodeTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/AbstractExporterNetworkNodeTest.java index e36a0c7f9..da0d68d44 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/AbstractExporterNetworkNodeTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/AbstractExporterNetworkNodeTest.java @@ -4,6 +4,7 @@ import com.refinedmods.refinedstorage2.api.network.energy.EnergyNetworkComponent; import com.refinedmods.refinedstorage2.api.network.node.exporter.ExporterTransferStrategy; import com.refinedmods.refinedstorage2.api.network.node.task.TaskExecutor; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.api.storage.Actor; @@ -11,11 +12,10 @@ import com.refinedmods.refinedstorage2.api.storage.InMemoryStorageImpl; import com.refinedmods.refinedstorage2.api.storage.InsertableStorage; import com.refinedmods.refinedstorage2.api.storage.Storage; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.api.storage.limited.LimitedStorageImpl; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; import com.refinedmods.refinedstorage2.network.test.InjectNetworkEnergyComponent; -import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageChannel; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageComponent; import com.refinedmods.refinedstorage2.network.test.NetworkTest; import com.refinedmods.refinedstorage2.network.test.SetupNetwork; @@ -24,9 +24,9 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A; -import static com.refinedmods.refinedstorage2.network.test.TestResource.B; -import static com.refinedmods.refinedstorage2.network.test.TestResource.C; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.B; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.C; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; @@ -55,12 +55,12 @@ void testInitialState() { @Test void shouldUseFirstSuccessfulStrategy( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); - storageChannel.insert(B, 100, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); + storage.insert(B, 100, Action.EXECUTE, EmptyActor.INSTANCE); final Storage failingDestination = new LimitedStorageImpl(0); final Storage destination = new LimitedStorageImpl(100); @@ -76,7 +76,7 @@ void shouldUseFirstSuccessfulStrategy( sut.doWork(); // Assert - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(A, 90), new ResourceAmount(B, 100) ); @@ -87,12 +87,12 @@ void shouldUseFirstSuccessfulStrategy( @Test void shouldUseFirstSuccessfulResourceInTheStrategy( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); - storageChannel.insert(B, 100, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); + storage.insert(B, 100, Action.EXECUTE, EmptyActor.INSTANCE); final Storage destination = new LimitedStorageImpl(100) { @Override @@ -113,7 +113,7 @@ public long insert(final ResourceKey resource, final long amount, final Action a sut.doWork(); // Assert - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(A, 90), new ResourceAmount(B, 100) ); @@ -142,12 +142,12 @@ void shouldNotTransferWithoutNetwork() { @Test void shouldNotTransferWithoutTaskExecutor( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); - storageChannel.insert(B, 100, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); + storage.insert(B, 100, Action.EXECUTE, EmptyActor.INSTANCE); final Storage destination = new InMemoryStorageImpl(); @@ -159,7 +159,7 @@ void shouldNotTransferWithoutTaskExecutor( sut.doWork(); // Assert - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(A, 100), new ResourceAmount(B, 100) ); @@ -167,11 +167,11 @@ void shouldNotTransferWithoutTaskExecutor( } @Test - void shouldNotTransferWithoutStrategy(@InjectNetworkStorageChannel final StorageChannel storageChannel) { + void shouldNotTransferWithoutStrategy(@InjectNetworkStorageComponent final StorageNetworkComponent storage) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); - storageChannel.insert(B, 100, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); + storage.insert(B, 100, Action.EXECUTE, EmptyActor.INSTANCE); final Storage destination = new InMemoryStorageImpl(); @@ -181,7 +181,7 @@ void shouldNotTransferWithoutStrategy(@InjectNetworkStorageChannel final Storage sut.doWork(); // Assert - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(A, 100), new ResourceAmount(B, 100) ); @@ -189,11 +189,11 @@ void shouldNotTransferWithoutStrategy(@InjectNetworkStorageChannel final Storage } @Test - void shouldNotTransferIfInactive(@InjectNetworkStorageChannel final StorageChannel storageChannel) { + void shouldNotTransferIfInactive(@InjectNetworkStorageComponent final StorageNetworkComponent storage) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); - storageChannel.insert(B, 100, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); + storage.insert(B, 100, Action.EXECUTE, EmptyActor.INSTANCE); final Storage destination = new InMemoryStorageImpl(); final ExporterTransferStrategy strategy = createTransferStrategy(destination, 1); @@ -206,7 +206,7 @@ void shouldNotTransferIfInactive(@InjectNetworkStorageChannel final StorageChann sut.doWork(); // Assert - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(A, 100), new ResourceAmount(B, 100) ); @@ -214,11 +214,11 @@ void shouldNotTransferIfInactive(@InjectNetworkStorageChannel final StorageChann } @Test - void shouldNotTransferWithoutFilters(@InjectNetworkStorageChannel final StorageChannel storageChannel) { + void shouldNotTransferWithoutFilters(@InjectNetworkStorageComponent final StorageNetworkComponent storage) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); - storageChannel.insert(B, 100, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); + storage.insert(B, 100, Action.EXECUTE, EmptyActor.INSTANCE); final Storage destination = new InMemoryStorageImpl(); final ExporterTransferStrategy strategy = createTransferStrategy(destination, 1); @@ -230,7 +230,7 @@ void shouldNotTransferWithoutFilters(@InjectNetworkStorageChannel final StorageC sut.doWork(); // Assert - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(A, 100), new ResourceAmount(B, 100) ); @@ -239,7 +239,7 @@ void shouldNotTransferWithoutFilters(@InjectNetworkStorageChannel final StorageC @Test void shouldNotTransferIfNoResourcesAreAvailable( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange final Storage destination = new InMemoryStorageImpl(); @@ -254,19 +254,19 @@ void shouldNotTransferIfNoResourcesAreAvailable( sut.doWork(); // Assert - assertThat(storageChannel.getAll()).isEmpty(); + assertThat(storage.getAll()).isEmpty(); assertThat(destination.getAll()).isEmpty(); } @Test void shouldTransferWithLimitedSpaceInDestination( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); - storageChannel.insert(B, 100, Action.EXECUTE, EmptyActor.INSTANCE); - storageChannel.insert(C, 100, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); + storage.insert(B, 100, Action.EXECUTE, EmptyActor.INSTANCE); + storage.insert(C, 100, Action.EXECUTE, EmptyActor.INSTANCE); final Storage destination = new LimitedStorageImpl(5); destination.insert(C, 1, Action.EXECUTE, EmptyActor.INSTANCE); @@ -280,7 +280,7 @@ void shouldTransferWithLimitedSpaceInDestination( // Act & assert sut.doWork(); - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(A, 96), new ResourceAmount(B, 100), new ResourceAmount(C, 100) @@ -292,7 +292,7 @@ void shouldTransferWithLimitedSpaceInDestination( sut.doWork(); - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(A, 96), new ResourceAmount(B, 100), new ResourceAmount(C, 100) @@ -305,12 +305,12 @@ void shouldTransferWithLimitedSpaceInDestination( @Test void shouldNotTransferIfThereIsNoSpaceInTheDestination( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); - storageChannel.insert(B, 100, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); + storage.insert(B, 100, Action.EXECUTE, EmptyActor.INSTANCE); final Storage destination = new LimitedStorageImpl(1); destination.insert(C, 1, Action.EXECUTE, EmptyActor.INSTANCE); @@ -324,7 +324,7 @@ void shouldNotTransferIfThereIsNoSpaceInTheDestination( sut.doWork(); // Assert - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(A, 100), new ResourceAmount(B, 100) ); @@ -335,12 +335,12 @@ void shouldNotTransferIfThereIsNoSpaceInTheDestination( @Test void shouldTransferSingleResourceEvenIfTransferQuotaHasNotBeenMet( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(A, 6, Action.EXECUTE, EmptyActor.INSTANCE); - storageChannel.insert(B, 7, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(A, 6, Action.EXECUTE, EmptyActor.INSTANCE); + storage.insert(B, 7, Action.EXECUTE, EmptyActor.INSTANCE); final Storage destination = new InMemoryStorageImpl(); final ExporterTransferStrategy strategy = createTransferStrategy(destination, 10); @@ -352,7 +352,7 @@ void shouldTransferSingleResourceEvenIfTransferQuotaHasNotBeenMet( sut.doWork(); // Assert - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( new ResourceAmount(B, 7) ); assertThat(destination.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/FirstAvailableExporterNetworkNodeTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/FirstAvailableExporterNetworkNodeTest.java index 4f94d158f..b993f78d3 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/FirstAvailableExporterNetworkNodeTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/FirstAvailableExporterNetworkNodeTest.java @@ -5,24 +5,24 @@ import com.refinedmods.refinedstorage2.api.network.node.NetworkNodeActor; import com.refinedmods.refinedstorage2.api.network.node.exporter.ExporterTransferStrategy; import com.refinedmods.refinedstorage2.api.network.node.task.TaskExecutor; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.api.storage.Actor; import com.refinedmods.refinedstorage2.api.storage.EmptyActor; import com.refinedmods.refinedstorage2.api.storage.InMemoryStorageImpl; import com.refinedmods.refinedstorage2.api.storage.Storage; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedResource; import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedStorageImpl; -import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageChannel; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageComponent; import java.util.List; import org.junit.jupiter.api.Test; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A; -import static com.refinedmods.refinedstorage2.network.test.TestResource.B; -import static com.refinedmods.refinedstorage2.network.test.TestResource.C; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.B; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.C; import static org.assertj.core.api.Assertions.assertThat; class FirstAvailableExporterNetworkNodeTest extends AbstractExporterNetworkNodeTest { @@ -32,11 +32,11 @@ protected TaskExecutor createTaskExecutor() { } @Test - void shouldTransfer(@InjectNetworkStorageChannel final StorageChannel storageChannel) { + void shouldTransfer(@InjectNetworkStorageComponent final StorageNetworkComponent storage) { // Arrange - storageChannel.addSource(new TrackedStorageImpl(new InMemoryStorageImpl(), () -> 1L)); - storageChannel.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); - storageChannel.insert(B, 100, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new TrackedStorageImpl(new InMemoryStorageImpl(), () -> 1L)); + storage.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); + storage.insert(B, 100, Action.EXECUTE, EmptyActor.INSTANCE); final Storage destination = new InMemoryStorageImpl(); final ExporterTransferStrategy strategy = createTransferStrategy(destination, 1); @@ -48,27 +48,27 @@ void shouldTransfer(@InjectNetworkStorageChannel final StorageChannel storageCha sut.doWork(); // Assert - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(A, 99), new ResourceAmount(B, 100) ); assertThat(destination.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( new ResourceAmount(A, 1) ); - assertThat(storageChannel.findTrackedResourceByActorType(A, NetworkNodeActor.class)) + assertThat(storage.findTrackedResourceByActorType(A, NetworkNodeActor.class)) .get() .usingRecursiveComparison() .isEqualTo(new TrackedResource(ExporterNetworkNode.class.getName(), 1)); - assertThat(storageChannel.findTrackedResourceByActorType(B, NetworkNodeActor.class)).isEmpty(); + assertThat(storage.findTrackedResourceByActorType(B, NetworkNodeActor.class)).isEmpty(); } @Test void shouldUseNextResourceIfFirstOneIsNotAvailableInSameCycle( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(B, 7, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(B, 7, Action.EXECUTE, EmptyActor.INSTANCE); final Storage destination = new InMemoryStorageImpl(); final ExporterTransferStrategy strategy = createTransferStrategy(destination, 10); @@ -80,7 +80,7 @@ void shouldUseNextResourceIfFirstOneIsNotAvailableInSameCycle( sut.doWork(); // Assert - assertThat(storageChannel.getAll()).isEmpty(); + assertThat(storage.getAll()).isEmpty(); assertThat(destination.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(B, 7) ); @@ -88,13 +88,13 @@ void shouldUseNextResourceIfFirstOneIsNotAvailableInSameCycle( @Test void shouldUseNextResourceIfFirstOneIsNotAcceptedInSameCycle( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); - storageChannel.insert(B, 10, Action.EXECUTE, EmptyActor.INSTANCE); - storageChannel.insert(C, 10, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); + storage.insert(B, 10, Action.EXECUTE, EmptyActor.INSTANCE); + storage.insert(C, 10, Action.EXECUTE, EmptyActor.INSTANCE); final Storage destination = new InMemoryStorageImpl() { @Override @@ -113,7 +113,7 @@ public long insert(final ResourceKey resource, final long amount, final Action a // Act & assert sut.doWork(); - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(A, 10), new ResourceAmount(C, 10) ); @@ -123,7 +123,7 @@ public long insert(final ResourceKey resource, final long amount, final Action a sut.doWork(); - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(A, 10) ); assertThat(destination.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( @@ -133,7 +133,7 @@ public long insert(final ResourceKey resource, final long amount, final Action a sut.doWork(); - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(A, 10) ); assertThat(destination.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/RandomExporterNetworkNodeTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/RandomExporterNetworkNodeTest.java index fe2e90ddc..8c78adcb9 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/RandomExporterNetworkNodeTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/RandomExporterNetworkNodeTest.java @@ -4,19 +4,19 @@ import com.refinedmods.refinedstorage2.api.network.impl.node.task.RandomTaskExecutor; import com.refinedmods.refinedstorage2.api.network.node.exporter.ExporterTransferStrategy; import com.refinedmods.refinedstorage2.api.network.node.task.TaskExecutor; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.storage.EmptyActor; import com.refinedmods.refinedstorage2.api.storage.InMemoryStorageImpl; import com.refinedmods.refinedstorage2.api.storage.Storage; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; -import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageChannel; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageComponent; import java.util.List; import org.junit.jupiter.api.Test; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A; -import static com.refinedmods.refinedstorage2.network.test.TestResource.B; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.B; import static org.assertj.core.api.Assertions.assertThat; class RandomExporterNetworkNodeTest extends AbstractExporterNetworkNodeTest { @@ -30,11 +30,11 @@ protected TaskExecutor createTaskExecutor() { } @Test - void shouldTransfer(@InjectNetworkStorageChannel final StorageChannel storageChannel) { + void shouldTransfer(@InjectNetworkStorageComponent final StorageNetworkComponent storage) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); - storageChannel.insert(B, 100, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); + storage.insert(B, 100, Action.EXECUTE, EmptyActor.INSTANCE); final Storage destination = new InMemoryStorageImpl(); final ExporterTransferStrategy strategy = createTransferStrategy(destination, 5); @@ -45,7 +45,7 @@ void shouldTransfer(@InjectNetworkStorageChannel final StorageChannel storageCha // Act & assert sut.doWork(); - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(A, 95), new ResourceAmount(B, 100) ); @@ -55,7 +55,7 @@ void shouldTransfer(@InjectNetworkStorageChannel final StorageChannel storageCha sut.doWork(); - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(A, 90), new ResourceAmount(B, 100) ); @@ -66,11 +66,11 @@ void shouldTransfer(@InjectNetworkStorageChannel final StorageChannel storageCha @Test void shouldUseNextResourceIfFirstOneIsNotAvailableInSameCycle( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(B, 7, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(B, 7, Action.EXECUTE, EmptyActor.INSTANCE); final Storage destination = new InMemoryStorageImpl(); final ExporterTransferStrategy strategy = createTransferStrategy(destination, 10); @@ -81,14 +81,14 @@ void shouldUseNextResourceIfFirstOneIsNotAvailableInSameCycle( // Act & assert sut.doWork(); - assertThat(storageChannel.getAll()).isEmpty(); + assertThat(storage.getAll()).isEmpty(); assertThat(destination.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(B, 7) ); sut.doWork(); - assertThat(storageChannel.getAll()).isEmpty(); + assertThat(storage.getAll()).isEmpty(); assertThat(destination.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(B, 7) ); diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/RoundRobinExporterNetworkNodeTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/RoundRobinExporterNetworkNodeTest.java index 278f6c6b3..d09f2cc24 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/RoundRobinExporterNetworkNodeTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/RoundRobinExporterNetworkNodeTest.java @@ -4,22 +4,22 @@ import com.refinedmods.refinedstorage2.api.network.impl.node.task.RoundRobinTaskExecutor; import com.refinedmods.refinedstorage2.api.network.node.exporter.ExporterTransferStrategy; import com.refinedmods.refinedstorage2.api.network.node.task.TaskExecutor; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.storage.EmptyActor; import com.refinedmods.refinedstorage2.api.storage.InMemoryStorageImpl; import com.refinedmods.refinedstorage2.api.storage.Storage; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; -import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageChannel; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageComponent; import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A; -import static com.refinedmods.refinedstorage2.network.test.TestResource.B; -import static com.refinedmods.refinedstorage2.network.test.TestResource.C; -import static com.refinedmods.refinedstorage2.network.test.TestResource.D; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.B; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.C; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.D; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; @@ -41,11 +41,11 @@ protected TaskExecutor createTaskExecutor() { } @Test - void shouldTransfer(@InjectNetworkStorageChannel final StorageChannel storageChannel) { + void shouldTransfer(@InjectNetworkStorageComponent final StorageNetworkComponent storage) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); - storageChannel.insert(B, 100, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); + storage.insert(B, 100, Action.EXECUTE, EmptyActor.INSTANCE); final Storage destination = new InMemoryStorageImpl(); final ExporterTransferStrategy strategy = createTransferStrategy(destination, 5); @@ -56,7 +56,7 @@ void shouldTransfer(@InjectNetworkStorageChannel final StorageChannel storageCha // Act & assert sut.doWork(); - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(A, 95), new ResourceAmount(B, 100) ); @@ -68,7 +68,7 @@ void shouldTransfer(@InjectNetworkStorageChannel final StorageChannel storageCha sut.doWork(); - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(A, 95), new ResourceAmount(B, 95) ); @@ -81,7 +81,7 @@ void shouldTransfer(@InjectNetworkStorageChannel final StorageChannel storageCha sut.doWork(); - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(A, 90), new ResourceAmount(B, 95) ); @@ -109,12 +109,12 @@ void shouldNotTransferIfThereAreNoResourcesInSource() { @Test void shouldUseNextResourceIfFirstOneIsNotAvailableInSameCycle( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(C, 8, Action.EXECUTE, EmptyActor.INSTANCE); - storageChannel.insert(D, 9, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(C, 8, Action.EXECUTE, EmptyActor.INSTANCE); + storage.insert(D, 9, Action.EXECUTE, EmptyActor.INSTANCE); final Storage destination = new InMemoryStorageImpl(); final ExporterTransferStrategy strategy = createTransferStrategy(destination, 10); @@ -125,7 +125,7 @@ void shouldUseNextResourceIfFirstOneIsNotAvailableInSameCycle( // Act & assert sut.doWork(); - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( new ResourceAmount(D, 9) ); assertThat(destination.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( @@ -134,7 +134,7 @@ void shouldUseNextResourceIfFirstOneIsNotAvailableInSameCycle( sut.doWork(); - assertThat(storageChannel.getAll()).isEmpty(); + assertThat(storage.getAll()).isEmpty(); assertThat(destination.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(C, 8), new ResourceAmount(D, 9) @@ -142,18 +142,18 @@ void shouldUseNextResourceIfFirstOneIsNotAvailableInSameCycle( sut.doWork(); - assertThat(storageChannel.getAll()).isEmpty(); + assertThat(storage.getAll()).isEmpty(); assertThat(destination.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(C, 8), new ResourceAmount(D, 9) ); - storageChannel.insert(A, 1, Action.EXECUTE, EmptyActor.INSTANCE); - storageChannel.insert(B, 2, Action.EXECUTE, EmptyActor.INSTANCE); + storage.insert(A, 1, Action.EXECUTE, EmptyActor.INSTANCE); + storage.insert(B, 2, Action.EXECUTE, EmptyActor.INSTANCE); sut.doWork(); - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( new ResourceAmount(B, 2) ); assertThat(destination.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( @@ -164,7 +164,7 @@ void shouldUseNextResourceIfFirstOneIsNotAvailableInSameCycle( sut.doWork(); - assertThat(storageChannel.getAll()).isEmpty(); + assertThat(storage.getAll()).isEmpty(); assertThat(destination.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(A, 1), new ResourceAmount(B, 2), @@ -174,7 +174,7 @@ void shouldUseNextResourceIfFirstOneIsNotAvailableInSameCycle( sut.doWork(); - assertThat(storageChannel.getAll()).isEmpty(); + assertThat(storage.getAll()).isEmpty(); assertThat(destination.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(A, 1), new ResourceAmount(B, 2), @@ -185,13 +185,13 @@ void shouldUseNextResourceIfFirstOneIsNotAvailableInSameCycle( @Test void shouldResetRoundRobinStateAfterChangingFilters( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); - storageChannel.insert(B, 100, Action.EXECUTE, EmptyActor.INSTANCE); - storageChannel.insert(C, 100, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); + storage.insert(B, 100, Action.EXECUTE, EmptyActor.INSTANCE); + storage.insert(C, 100, Action.EXECUTE, EmptyActor.INSTANCE); final Storage destination = new InMemoryStorageImpl(); final ExporterTransferStrategy strategy = createTransferStrategy(destination, 5); @@ -202,7 +202,7 @@ void shouldResetRoundRobinStateAfterChangingFilters( // Act & assert sut.doWork(); - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(A, 95), new ResourceAmount(B, 100), new ResourceAmount(C, 100) @@ -213,7 +213,7 @@ void shouldResetRoundRobinStateAfterChangingFilters( sut.doWork(); - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(A, 95), new ResourceAmount(B, 95), new ResourceAmount(C, 100) @@ -227,7 +227,7 @@ void shouldResetRoundRobinStateAfterChangingFilters( sut.setFilters(List.of(A, C)); sut.doWork(); - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(A, 90), new ResourceAmount(B, 95), new ResourceAmount(C, 100) diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/externalstorage/ExternalStorageNetworkNodeTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/externalstorage/ExternalStorageNetworkNodeTest.java index bc6bff232..218848016 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/externalstorage/ExternalStorageNetworkNodeTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/externalstorage/ExternalStorageNetworkNodeTest.java @@ -2,23 +2,23 @@ import com.refinedmods.refinedstorage2.api.core.Action; import com.refinedmods.refinedstorage2.api.network.Network; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.resource.filter.FilterMode; import com.refinedmods.refinedstorage2.api.storage.AccessMode; import com.refinedmods.refinedstorage2.api.storage.EmptyActor; import com.refinedmods.refinedstorage2.api.storage.InMemoryStorageImpl; import com.refinedmods.refinedstorage2.api.storage.Storage; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.api.storage.external.ExternalStorageProvider; import com.refinedmods.refinedstorage2.api.storage.limited.LimitedStorageImpl; import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedResource; import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedStorageImpl; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; import com.refinedmods.refinedstorage2.network.test.InjectNetwork; -import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageChannel; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageComponent; import com.refinedmods.refinedstorage2.network.test.NetworkTest; import com.refinedmods.refinedstorage2.network.test.SetupNetwork; -import com.refinedmods.refinedstorage2.network.test.util.FakeActor; +import com.refinedmods.refinedstorage2.network.test.fake.FakeActor; import java.util.Optional; import java.util.Set; @@ -30,9 +30,9 @@ import org.junit.jupiter.params.provider.EnumSource; import org.junit.jupiter.params.provider.ValueSource; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A; -import static com.refinedmods.refinedstorage2.network.test.TestResource.B; -import static com.refinedmods.refinedstorage2.network.test.TestResource.C; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.B; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.C; import static com.refinedmods.refinedstorage2.network.test.nodefactory.AbstractNetworkNodeFactory.PROPERTY_ENERGY_USAGE; import static org.assertj.core.api.Assertions.assertThat; @@ -48,7 +48,7 @@ class ExternalStorageNetworkNodeTest { ExternalStorageNetworkNode sut; @Test - void testInitialState(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void testInitialState(@InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Act final long inserted = networkStorage.insert(A, 10, Action.EXECUTE, FakeActor.INSTANCE); final long extracted = networkStorage.extract(A, 10, Action.EXECUTE, FakeActor.INSTANCE); @@ -66,7 +66,7 @@ void testInitialState(@InjectNetworkStorageChannel final StorageChannel networkS } @Test - void shouldInitialize(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void shouldInitialize(@InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange final Storage storage = new InMemoryStorageImpl(); final ExternalStorageProvider provider = new StorageExternalStorageProvider(storage); @@ -81,7 +81,7 @@ void shouldInitialize(@InjectNetworkStorageChannel final StorageChannel networkS @Test void shouldBeAbleToInitializeMultipleTimes( - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange final Storage storage1 = new InMemoryStorageImpl(); @@ -111,7 +111,7 @@ void shouldBeAbleToInitializeMultipleTimes( } @Test - void shouldInsert(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void shouldInsert(@InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange final Storage storage = new InMemoryStorageImpl(); final ExternalStorageProvider provider = new StorageExternalStorageProvider(storage); @@ -132,7 +132,7 @@ void shouldInsert(@InjectNetworkStorageChannel final StorageChannel networkStora } @Test - void shouldExtract(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void shouldExtract(@InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange final Storage storage = new InMemoryStorageImpl(); storage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); @@ -154,7 +154,8 @@ void shouldExtract(@InjectNetworkStorageChannel final StorageChannel networkStor } @Test - void shouldRespectAllowlistWhenInserting(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void shouldRespectAllowlistWhenInserting( + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange sut.setFilterMode(FilterMode.ALLOW); sut.setFilters(Set.of(A, B)); @@ -176,7 +177,7 @@ void shouldRespectAllowlistWhenInserting(@InjectNetworkStorageChannel final Stor @Test void shouldRespectEmptyAllowlistWhenInserting( - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange sut.setFilterMode(FilterMode.ALLOW); @@ -198,7 +199,8 @@ void shouldRespectEmptyAllowlistWhenInserting( } @Test - void shouldRespectBlocklistWhenInserting(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void shouldRespectBlocklistWhenInserting( + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange sut.setFilterMode(FilterMode.BLOCK); sut.setFilters(Set.of(A, B)); @@ -220,7 +222,7 @@ void shouldRespectBlocklistWhenInserting(@InjectNetworkStorageChannel final Stor @Test void shouldRespectEmptyBlocklistWhenInserting( - @InjectNetworkStorageChannel final StorageChannel networkStorage) { + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange sut.setFilterMode(FilterMode.BLOCK); sut.setFilters(Set.of()); @@ -243,7 +245,8 @@ void shouldRespectEmptyBlocklistWhenInserting( @ParameterizedTest @EnumSource(AccessMode.class) void shouldRespectAccessModeWhenInserting(final AccessMode accessMode, - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent + final StorageNetworkComponent networkStorage ) { // Arrange sut.setAccessMode(accessMode); @@ -265,7 +268,8 @@ void shouldRespectAccessModeWhenInserting(final AccessMode accessMode, @ParameterizedTest @EnumSource(AccessMode.class) void shouldRespectAccessModeWhenExtracting(final AccessMode accessMode, - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent + final StorageNetworkComponent networkStorage ) { // Arrange sut.setAccessMode(accessMode); @@ -287,7 +291,7 @@ void shouldRespectAccessModeWhenExtracting(final AccessMode accessMode, } @Test - void shouldNotInsertWhenInactive(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void shouldNotInsertWhenInactive(@InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange final Storage storage = new InMemoryStorageImpl(); final ExternalStorageProvider provider = new StorageExternalStorageProvider(storage); @@ -303,7 +307,7 @@ void shouldNotInsertWhenInactive(@InjectNetworkStorageChannel final StorageChann } @Test - void shouldNotExtractWhenInactive(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void shouldNotExtractWhenInactive(@InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange final Storage storage = new InMemoryStorageImpl(); storage.insert(A, 5, Action.EXECUTE, EmptyActor.INSTANCE); @@ -321,7 +325,7 @@ void shouldNotExtractWhenInactive(@InjectNetworkStorageChannel final StorageChan @Test void shouldHideStorageContentsWhenInactive( - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange final Storage storage = new LimitedStorageImpl(100); @@ -340,7 +344,8 @@ void shouldHideStorageContentsWhenInactive( } @Test - void shouldShowStorageContentsWhenActive(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void shouldShowStorageContentsWhenActive( + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange final Storage storage = new LimitedStorageImpl(100); final ExternalStorageProvider provider = new StorageExternalStorageProvider(storage); @@ -363,7 +368,7 @@ void shouldShowStorageContentsWhenActive(@InjectNetworkStorageChannel final Stor @Test void shouldNoLongerShowOnNetworkWhenRemoved( - @InjectNetworkStorageChannel final StorageChannel networkStorage, + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage, @InjectNetwork final Network network ) { // Arrange @@ -384,8 +389,8 @@ void shouldNoLongerShowOnNetworkWhenRemoved( @Test void shouldNotifyNewNetworkAboutChangesWhenChangingNetworks( - @InjectNetworkStorageChannel final StorageChannel networkStorage, - @InjectNetworkStorageChannel(networkId = "other") final StorageChannel otherNetworkStorage, + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage, + @InjectNetworkStorageComponent(networkId = "other") final StorageNetworkComponent otherNetworkStorage, @InjectNetwork final Network network, @InjectNetwork("other") final Network otherNetwork ) { @@ -415,8 +420,8 @@ void shouldNotifyNewNetworkAboutChangesWhenChangingNetworks( @Test void shouldNoLongerNotifyOldNetworkAboutChangesWhenChangingNetworks( - @InjectNetworkStorageChannel final StorageChannel networkStorage, - @InjectNetworkStorageChannel(networkId = "other") final StorageChannel otherNetworkStorage, + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage, + @InjectNetworkStorageComponent(networkId = "other") final StorageNetworkComponent otherNetworkStorage, @InjectNetwork final Network network, @InjectNetwork("other") final Network otherNetwork ) { @@ -450,7 +455,7 @@ void shouldNoLongerNotifyOldNetworkAboutChangesWhenChangingNetworks( @Test void shouldNoLongerShowOnNetworkWhenRemovedWithoutInitializedStorage( - @InjectNetworkStorageChannel final StorageChannel networkStorage, + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage, @InjectNetwork final Network network ) { // Act @@ -465,7 +470,7 @@ void shouldNoLongerShowOnNetworkWhenRemovedWithoutInitializedStorage( @EnumSource(Action.class) void shouldTrackChangesWhenExtracting( final Action action, - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange final Storage storage = new LimitedStorageImpl(100); @@ -502,7 +507,7 @@ void shouldTrackChangesWhenExtracting( @EnumSource(Action.class) void shouldNotTrackChangesWhenExtractionFailed( final Action action, - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange final Storage storage = new LimitedStorageImpl(100); @@ -525,7 +530,7 @@ void shouldNotTrackChangesWhenExtractionFailed( @EnumSource(Action.class) void shouldTrackChangesWhenInserting( final Action action, - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange final Storage storage = new LimitedStorageImpl(100); @@ -561,7 +566,7 @@ void shouldTrackChangesWhenInserting( @EnumSource(Action.class) void shouldNotTrackChangesWhenInsertionFailed( final Action action, - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange final Storage storage = new LimitedStorageImpl(0); @@ -581,7 +586,7 @@ void shouldNotTrackChangesWhenInsertionFailed( } private AtomicBoolean trackWhetherResourceHasChangedAndTrackedResourceIsAvailable( - final StorageChannel networkStorage + final StorageNetworkComponent networkStorage ) { final AtomicBoolean found = new AtomicBoolean(); networkStorage.addListener(change -> { @@ -602,7 +607,7 @@ void shouldNotDetectChangesWithoutConnectedStorage() { } @Test - void shouldDetectChanges(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void shouldDetectChanges(@InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange final Storage storage = new LimitedStorageImpl(100); final ExternalStorageProvider provider = new StorageExternalStorageProvider(storage); @@ -631,7 +636,7 @@ class PriorityTest { @ParameterizedTest @ValueSource(booleans = {true, false}) void shouldRespectPriority(final boolean oneHasPriority, - @InjectNetworkStorageChannel final StorageChannel networkStorage) { + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange final Storage storage1 = new TrackedStorageImpl(new LimitedStorageImpl(100), () -> 0L); final ExternalStorageProvider provider1 = new StorageExternalStorageProvider(storage1); diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/grid/GridNetworkNodeTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/grid/GridNetworkNodeTest.java index c90aa1436..5d28eab96 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/grid/GridNetworkNodeTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/grid/GridNetworkNodeTest.java @@ -3,30 +3,30 @@ import com.refinedmods.refinedstorage2.api.core.Action; import com.refinedmods.refinedstorage2.api.grid.watcher.GridWatcher; import com.refinedmods.refinedstorage2.api.network.Network; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.api.storage.Actor; import com.refinedmods.refinedstorage2.api.storage.EmptyActor; import com.refinedmods.refinedstorage2.api.storage.InMemoryStorageImpl; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.api.storage.limited.LimitedStorageImpl; import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedResource; import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedStorageImpl; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; import com.refinedmods.refinedstorage2.network.test.InjectNetwork; -import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageChannel; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageComponent; import com.refinedmods.refinedstorage2.network.test.NetworkTest; import com.refinedmods.refinedstorage2.network.test.SetupNetwork; +import com.refinedmods.refinedstorage2.network.test.fake.FakeActor; import com.refinedmods.refinedstorage2.network.test.nodefactory.AbstractNetworkNodeFactory; -import com.refinedmods.refinedstorage2.network.test.util.FakeActor; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A; -import static com.refinedmods.refinedstorage2.network.test.TestResource.B; -import static com.refinedmods.refinedstorage2.network.test.TestResource.C; -import static com.refinedmods.refinedstorage2.network.test.TestResource.D; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.B; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.C; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.D; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.anyLong; @@ -48,14 +48,14 @@ class GridNetworkNodeTest { @BeforeEach void setUp( - @InjectNetworkStorageChannel final StorageChannel storage, - @InjectNetworkStorageChannel(networkId = "other") final StorageChannel otherStorageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage, + @InjectNetworkStorageComponent(networkId = "other") final StorageNetworkComponent otherStorage ) { storage.addSource(new TrackedStorageImpl(new LimitedStorageImpl(1000), () -> 2L)); storage.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); storage.insert(B, 200, Action.EXECUTE, EmptyActor.INSTANCE); - otherStorageChannel.addSource(new TrackedStorageImpl(new InMemoryStorageImpl(), () -> 3L)); + otherStorage.addSource(new TrackedStorageImpl(new InMemoryStorageImpl(), () -> 3L)); } @Test @@ -85,7 +85,7 @@ void shouldNotifyWatchersOfActivenessChanges() { @Test void shouldNotifyWatchersOfStorageChanges( - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange final GridWatcher watcher = mock(GridWatcher.class); @@ -141,8 +141,8 @@ void shouldNotBeAbleToAddDuplicateWatcher() { void shouldDetachWatchersFromOldNetworkAndReattachToNewNetwork( @InjectNetwork("other") final Network otherNetwork, @InjectNetwork final Network network, - @InjectNetworkStorageChannel final StorageChannel storageChannel, - @InjectNetworkStorageChannel(networkId = "other") final StorageChannel otherStorageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage, + @InjectNetworkStorageComponent(networkId = "other") final StorageNetworkComponent otherStorage ) { // Arrange final GridWatcher watcher = mock(GridWatcher.class); @@ -150,19 +150,19 @@ void shouldDetachWatchersFromOldNetworkAndReattachToNewNetwork( // Act // This one shouldn't be ignored! - otherStorageChannel.insert(C, 10, Action.EXECUTE, FakeActor.INSTANCE); + otherStorage.insert(C, 10, Action.EXECUTE, FakeActor.INSTANCE); sut.setNetwork(otherNetwork); network.removeContainer(() -> sut); otherNetwork.addContainer(() -> sut); // these one shouldn't be ignored either - otherStorageChannel.insert(A, 10, Action.EXECUTE, FakeActor.INSTANCE); - otherStorageChannel.insert(D, 10, Action.EXECUTE, EmptyActor.INSTANCE); + otherStorage.insert(A, 10, Action.EXECUTE, FakeActor.INSTANCE); + otherStorage.insert(D, 10, Action.EXECUTE, EmptyActor.INSTANCE); // these should be ignored - storageChannel.insert(B, 10, Action.EXECUTE, FakeActor.INSTANCE); - storageChannel.insert(D, 10, Action.EXECUTE, EmptyActor.INSTANCE); + storage.insert(B, 10, Action.EXECUTE, FakeActor.INSTANCE); + storage.insert(D, 10, Action.EXECUTE, EmptyActor.INSTANCE); // Assert verify(watcher, times(1)).invalidate(); diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/ClearSlotInterfaceNetworkNodeTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/ClearSlotInterfaceNetworkNodeTest.java index 673d43a55..27a2b136a 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/ClearSlotInterfaceNetworkNodeTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/ClearSlotInterfaceNetworkNodeTest.java @@ -1,19 +1,19 @@ package com.refinedmods.refinedstorage2.api.network.impl.node.iface; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.storage.InMemoryStorageImpl; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.api.storage.limited.LimitedStorageImpl; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; -import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageChannel; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageComponent; import com.refinedmods.refinedstorage2.network.test.NetworkTest; import com.refinedmods.refinedstorage2.network.test.SetupNetwork; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A; -import static com.refinedmods.refinedstorage2.network.test.TestResource.B; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.B; import static org.assertj.core.api.Assertions.assertThat; @NetworkTest @@ -34,10 +34,10 @@ void setUp() { @Test void shouldClearSlotWhenNoLongerRequestingAnything( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); + storage.addSource(new InMemoryStorageImpl()); exportState.setCurrentlyExported(1, A, 7); exportState.setCurrentlyExported(2, B, 2); @@ -48,7 +48,7 @@ void shouldClearSlotWhenNoLongerRequestingAnything( assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(5); assertThat(exportState.getExportedResource(2)).isNull(); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactlyInAnyOrder( new ResourceAmount(A, 2), @@ -60,7 +60,7 @@ void shouldClearSlotWhenNoLongerRequestingAnything( assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(3); assertThat(exportState.getExportedResource(2)).isNull(); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactlyInAnyOrder( new ResourceAmount(A, 4), @@ -72,7 +72,7 @@ void shouldClearSlotWhenNoLongerRequestingAnything( assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(1); assertThat(exportState.getExportedResource(2)).isNull(); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactlyInAnyOrder( new ResourceAmount(A, 6), @@ -83,7 +83,7 @@ void shouldClearSlotWhenNoLongerRequestingAnything( assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isNull(); assertThat(exportState.getExportedResource(2)).isNull(); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactlyInAnyOrder( new ResourceAmount(A, 7), @@ -96,7 +96,7 @@ void shouldClearSlotWhenNoLongerRequestingAnything( assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isNull(); assertThat(exportState.getExportedResource(2)).isNull(); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactlyInAnyOrder( new ResourceAmount(A, 7), @@ -106,10 +106,10 @@ void shouldClearSlotWhenNoLongerRequestingAnything( @Test void shouldClearSlotPartiallyWhenNoLongerRequestingAnythingButNetworkDoesNotHaveEnoughSpace( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new LimitedStorageImpl(3)); + storage.addSource(new LimitedStorageImpl(3)); exportState.setCurrentlyExported(1, A, 7); @@ -119,7 +119,7 @@ void shouldClearSlotPartiallyWhenNoLongerRequestingAnythingButNetworkDoesNotHave assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(5); assertThat(exportState.getExportedResource(2)).isNull(); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactly(new ResourceAmount(A, 2)); @@ -128,7 +128,7 @@ void shouldClearSlotPartiallyWhenNoLongerRequestingAnythingButNetworkDoesNotHave assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(4); assertThat(exportState.getExportedResource(2)).isNull(); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactly(new ResourceAmount(A, 3)); @@ -139,14 +139,14 @@ void shouldClearSlotPartiallyWhenNoLongerRequestingAnythingButNetworkDoesNotHave assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(4); assertThat(exportState.getExportedResource(2)).isNull(); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactly(new ResourceAmount(A, 3)); } @Test void shouldNotClearSlotWhenNoLongerRequestingAnythingAndNetworkDoesNotHaveEnoughSpace( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange exportState.setCurrentlyExported(1, A, 7); @@ -160,6 +160,6 @@ void shouldNotClearSlotWhenNoLongerRequestingAnythingAndNetworkDoesNotHaveEnough assertThat(exportState.getExportedAmount(1)).isEqualTo(7); assertThat(exportState.getExportedResource(2)).isNull(); - assertThat(storageChannel.getAll()).isEmpty(); + assertThat(storage.getAll()).isEmpty(); } } diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/ExportToEmptySlotInterfaceNetworkNodeTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/ExportToEmptySlotInterfaceNetworkNodeTest.java index 7a41bd42b..a54ed32c7 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/ExportToEmptySlotInterfaceNetworkNodeTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/ExportToEmptySlotInterfaceNetworkNodeTest.java @@ -1,22 +1,22 @@ package com.refinedmods.refinedstorage2.api.network.impl.node.iface; import com.refinedmods.refinedstorage2.api.core.Action; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.storage.EmptyActor; import com.refinedmods.refinedstorage2.api.storage.InMemoryStorageImpl; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; -import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageChannel; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageComponent; import com.refinedmods.refinedstorage2.network.test.NetworkTest; import com.refinedmods.refinedstorage2.network.test.SetupNetwork; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A_ALTERNATIVE; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A_ALTERNATIVE2; -import static com.refinedmods.refinedstorage2.network.test.TestResource.B; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A_ALTERNATIVE; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A_ALTERNATIVE2; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.B; import static org.assertj.core.api.Assertions.assertThat; @NetworkTest @@ -37,7 +37,7 @@ void setUp() { @Test void shouldNotExportToEmptySlotWhenRequestedIsNotAvailable( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange exportState.setRequestedResource(1, A, 1); @@ -50,16 +50,16 @@ void shouldNotExportToEmptySlotWhenRequestedIsNotAvailable( assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isNull(); assertThat(exportState.getExportedResource(2)).isNull(); - assertThat(storageChannel.getAll()).isEmpty(); + assertThat(storage.getAll()).isEmpty(); } @Test void shouldExportToEmptySlotWhenRequestedIsNotEntirelyAvailable( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(A, 2, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(A, 2, Action.EXECUTE, EmptyActor.INSTANCE); exportState.setRequestedResource(1, A, 10); @@ -74,16 +74,16 @@ void shouldExportToEmptySlotWhenRequestedIsNotEntirelyAvailable( assertThat(exportState.getExportedAmount(1)).isEqualTo(2); assertThat(exportState.getExportedResource(2)).isNull(); - assertThat(storageChannel.getAll()).isEmpty(); + assertThat(storage.getAll()).isEmpty(); } @Test void shouldExportToEmptySlotWhenRequestedIsLessThanTransferQuota( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); exportState.setRequestedResource(1, A, 1); @@ -96,19 +96,19 @@ void shouldExportToEmptySlotWhenRequestedIsLessThanTransferQuota( assertThat(exportState.getExportedAmount(1)).isEqualTo(1); assertThat(exportState.getExportedResource(2)).isNull(); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactly(new ResourceAmount(A, 9)); } @Test void shouldExportToEmptySlot( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); - storageChannel.insert(B, 10, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); + storage.insert(B, 10, Action.EXECUTE, EmptyActor.INSTANCE); exportState.setRequestedResource(1, A, 7); exportState.setRequestedResource(2, B, 2); @@ -123,7 +123,7 @@ void shouldExportToEmptySlot( assertThat(exportState.getExportedResource(2)).isEqualTo(B); assertThat(exportState.getExportedAmount(2)).isEqualTo(2); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactlyInAnyOrder( new ResourceAmount(A, 8), @@ -133,12 +133,12 @@ void shouldExportToEmptySlot( @Test void shouldExportResourceFuzzilyToEmptySlot( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(A_ALTERNATIVE, 10, Action.EXECUTE, EmptyActor.INSTANCE); - storageChannel.insert(A_ALTERNATIVE2, 10, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(A_ALTERNATIVE, 10, Action.EXECUTE, EmptyActor.INSTANCE); + storage.insert(A_ALTERNATIVE2, 10, Action.EXECUTE, EmptyActor.INSTANCE); exportState.setRequestedResource(1, A, 10); @@ -151,7 +151,7 @@ void shouldExportResourceFuzzilyToEmptySlot( assertThat(exportState.getExportedAmount(1)).isEqualTo(2); assertThat(exportState.getExportedResource(2)).isNull(); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactlyInAnyOrder( new ResourceAmount(A_ALTERNATIVE, 8), diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/InterfaceExportStateImpl.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/InterfaceExportStateImpl.java index df0b48887..ed4e50d7c 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/InterfaceExportStateImpl.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/InterfaceExportStateImpl.java @@ -13,9 +13,9 @@ import java.util.Map; import javax.annotation.Nullable; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A_ALTERNATIVE; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A_ALTERNATIVE2; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A_ALTERNATIVE; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A_ALTERNATIVE2; public class InterfaceExportStateImpl implements InterfaceExportState { private final Map requested = new HashMap<>(); diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/InterfaceNetworkNodeTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/InterfaceNetworkNodeTest.java index 7365d7687..3ce965776 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/InterfaceNetworkNodeTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/InterfaceNetworkNodeTest.java @@ -2,20 +2,20 @@ import com.refinedmods.refinedstorage2.api.core.Action; import com.refinedmods.refinedstorage2.api.network.energy.EnergyNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.storage.EmptyActor; import com.refinedmods.refinedstorage2.api.storage.InMemoryStorageImpl; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; import com.refinedmods.refinedstorage2.network.test.InjectNetworkEnergyComponent; -import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageChannel; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageComponent; import com.refinedmods.refinedstorage2.network.test.NetworkTest; import com.refinedmods.refinedstorage2.network.test.SetupNetwork; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A; import static org.assertj.core.api.Assertions.assertThat; @NetworkTest @@ -46,12 +46,12 @@ void shouldExtractEnergy( @Test void shouldExportAllWithDefaultTransferQuota( - @InjectNetworkStorageChannel final StorageChannel storageChannel, + @InjectNetworkStorageComponent final StorageNetworkComponent storage, @InjectNetworkEnergyComponent final EnergyNetworkComponent energy ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(A, Long.MAX_VALUE, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(A, Long.MAX_VALUE, Action.EXECUTE, EmptyActor.INSTANCE); exportState.setRequestedResource(1, A, Long.MAX_VALUE); @@ -62,18 +62,18 @@ void shouldExportAllWithDefaultTransferQuota( assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(Long.MAX_VALUE); - assertThat(storageChannel.getAll()).isEmpty(); + assertThat(storage.getAll()).isEmpty(); assertThat(energy.getStored()).isEqualTo(1000 - 5); } @Test void shouldNotExportAnythingWithoutBeingActive( - @InjectNetworkStorageChannel final StorageChannel storageChannel, + @InjectNetworkStorageComponent final StorageNetworkComponent storage, @InjectNetworkEnergyComponent final EnergyNetworkComponent energy ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); exportState.setRequestedResource(1, A, 1); @@ -86,7 +86,7 @@ void shouldNotExportAnythingWithoutBeingActive( // Assert assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isNull(); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactly(new ResourceAmount(A, 10)); assertThat(energy.getStored()).isEqualTo(1000); @@ -94,12 +94,12 @@ void shouldNotExportAnythingWithoutBeingActive( @Test void shouldNotExportAnythingWithoutNetwork( - @InjectNetworkStorageChannel final StorageChannel storageChannel, + @InjectNetworkStorageComponent final StorageNetworkComponent storage, @InjectNetworkEnergyComponent final EnergyNetworkComponent energy ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); exportState.setRequestedResource(1, A, 1); @@ -112,7 +112,7 @@ void shouldNotExportAnythingWithoutNetwork( // Assert assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isNull(); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactly(new ResourceAmount(A, 10)); assertThat(energy.getStored()).isEqualTo(1000); @@ -120,12 +120,12 @@ void shouldNotExportAnythingWithoutNetwork( @Test void shouldNotExportAnythingWithoutExportState( - @InjectNetworkStorageChannel final StorageChannel storageChannel, + @InjectNetworkStorageComponent final StorageNetworkComponent storage, @InjectNetworkEnergyComponent final EnergyNetworkComponent energy ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); sut.setExportState(null); sut.setTransferQuotaProvider(resource -> 2); @@ -136,7 +136,7 @@ void shouldNotExportAnythingWithoutExportState( // Assert assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isNull(); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactly(new ResourceAmount(A, 10)); assertThat(energy.getStored()).isEqualTo(1000 - 5); diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/KeepExportingInterfaceNetworkNodeTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/KeepExportingInterfaceNetworkNodeTest.java index 78d1d5ace..14886930f 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/KeepExportingInterfaceNetworkNodeTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/KeepExportingInterfaceNetworkNodeTest.java @@ -1,23 +1,23 @@ package com.refinedmods.refinedstorage2.api.network.impl.node.iface; import com.refinedmods.refinedstorage2.api.core.Action; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.storage.EmptyActor; import com.refinedmods.refinedstorage2.api.storage.InMemoryStorageImpl; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.api.storage.limited.LimitedStorageImpl; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; -import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageChannel; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageComponent; import com.refinedmods.refinedstorage2.network.test.NetworkTest; import com.refinedmods.refinedstorage2.network.test.SetupNetwork; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A_ALTERNATIVE; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A_ALTERNATIVE2; -import static com.refinedmods.refinedstorage2.network.test.TestResource.B; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A_ALTERNATIVE; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A_ALTERNATIVE2; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.B; import static org.assertj.core.api.Assertions.assertThat; @NetworkTest @@ -38,11 +38,11 @@ void setUp() { @Test void shouldKeepExportingResourceUntilWantedAmountIsReached( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); exportState.setRequestedResource(1, A, 7); @@ -51,7 +51,7 @@ void shouldKeepExportingResourceUntilWantedAmountIsReached( assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(2); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactly(new ResourceAmount(A, 8)); @@ -59,7 +59,7 @@ void shouldKeepExportingResourceUntilWantedAmountIsReached( assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(4); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactly(new ResourceAmount(A, 6)); @@ -67,7 +67,7 @@ void shouldKeepExportingResourceUntilWantedAmountIsReached( assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(6); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactly(new ResourceAmount(A, 4)); @@ -75,7 +75,7 @@ void shouldKeepExportingResourceUntilWantedAmountIsReached( assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(7); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactly(new ResourceAmount(A, 3)); @@ -85,18 +85,18 @@ void shouldKeepExportingResourceUntilWantedAmountIsReached( assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(7); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactly(new ResourceAmount(A, 3)); } @Test void shouldKeepExportingResourceUntilWantedAmountIsReachedAndNetworkHasEnoughResources( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(A, 7, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(A, 7, Action.EXECUTE, EmptyActor.INSTANCE); exportState.setRequestedResource(1, A, 10); @@ -105,7 +105,7 @@ void shouldKeepExportingResourceUntilWantedAmountIsReachedAndNetworkHasEnoughRes assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(2); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactly(new ResourceAmount(A, 5)); @@ -113,7 +113,7 @@ void shouldKeepExportingResourceUntilWantedAmountIsReachedAndNetworkHasEnoughRes assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(4); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactly(new ResourceAmount(A, 3)); @@ -121,7 +121,7 @@ void shouldKeepExportingResourceUntilWantedAmountIsReachedAndNetworkHasEnoughRes assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(6); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactly(new ResourceAmount(A, 1)); @@ -129,7 +129,7 @@ void shouldKeepExportingResourceUntilWantedAmountIsReachedAndNetworkHasEnoughRes assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(7); - assertThat(storageChannel.getAll()).isEmpty(); + assertThat(storage.getAll()).isEmpty(); sut.doWork(); sut.doWork(); @@ -137,17 +137,17 @@ void shouldKeepExportingResourceUntilWantedAmountIsReachedAndNetworkHasEnoughRes assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(7); - assertThat(storageChannel.getAll()).isEmpty(); + assertThat(storage.getAll()).isEmpty(); } @Test void shouldKeepExportingResourceFuzzilyUntilWantedAmountIsReached( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(A_ALTERNATIVE, 10, Action.EXECUTE, EmptyActor.INSTANCE); - storageChannel.insert(A_ALTERNATIVE2, 10, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(A_ALTERNATIVE, 10, Action.EXECUTE, EmptyActor.INSTANCE); + storage.insert(A_ALTERNATIVE2, 10, Action.EXECUTE, EmptyActor.INSTANCE); exportState.setRequestedResource(1, A, 10); @@ -156,7 +156,7 @@ void shouldKeepExportingResourceFuzzilyUntilWantedAmountIsReached( assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isEqualTo(A_ALTERNATIVE); assertThat(exportState.getExportedAmount(1)).isEqualTo(2); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactlyInAnyOrder( new ResourceAmount(A_ALTERNATIVE, 8), @@ -167,7 +167,7 @@ void shouldKeepExportingResourceFuzzilyUntilWantedAmountIsReached( assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isEqualTo(A_ALTERNATIVE); assertThat(exportState.getExportedAmount(1)).isEqualTo(4); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactlyInAnyOrder( new ResourceAmount(A_ALTERNATIVE, 6), @@ -177,11 +177,11 @@ void shouldKeepExportingResourceFuzzilyUntilWantedAmountIsReached( @Test void shouldKeepExportingResourceFuzzilyUntilWantedAmountIsReachedEvenIfTheResourceIsNoLongerAvailableInTheNetwork( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(A_ALTERNATIVE, 1, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(A_ALTERNATIVE, 1, Action.EXECUTE, EmptyActor.INSTANCE); exportState.setRequestedResource(1, A, 1); @@ -190,21 +190,21 @@ void shouldKeepExportingResourceFuzzilyUntilWantedAmountIsReachedEvenIfTheResour assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isEqualTo(A_ALTERNATIVE); assertThat(exportState.getExportedAmount(1)).isEqualTo(1); - assertThat(storageChannel.getAll()).isEmpty(); + assertThat(storage.getAll()).isEmpty(); sut.doWork(); assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isEqualTo(A_ALTERNATIVE); assertThat(exportState.getExportedAmount(1)).isEqualTo(1); - assertThat(storageChannel.getAll()).isEmpty(); + assertThat(storage.getAll()).isEmpty(); } @Test void shouldReturnResourceToNetworkUntilWantedAmountIsReached( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); + storage.addSource(new InMemoryStorageImpl()); exportState.setRequestedResource(1, A, 7); exportState.setCurrentlyExported(1, A, 10); @@ -214,7 +214,7 @@ void shouldReturnResourceToNetworkUntilWantedAmountIsReached( assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(8); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactly(new ResourceAmount(A, 2)); @@ -222,7 +222,7 @@ void shouldReturnResourceToNetworkUntilWantedAmountIsReached( assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(7); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactly(new ResourceAmount(A, 3)); @@ -232,17 +232,17 @@ void shouldReturnResourceToNetworkUntilWantedAmountIsReached( assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(7); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactly(new ResourceAmount(A, 3)); } @Test void shouldReturnResourceToNetworkUntilWantedAmountIsReachedAndNetworkIsFull( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new LimitedStorageImpl(3)); + storage.addSource(new LimitedStorageImpl(3)); exportState.setRequestedResource(1, A, 5); exportState.setCurrentlyExported(1, A, 10); @@ -252,7 +252,7 @@ void shouldReturnResourceToNetworkUntilWantedAmountIsReachedAndNetworkIsFull( assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(8); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactly(new ResourceAmount(A, 2)); @@ -260,7 +260,7 @@ void shouldReturnResourceToNetworkUntilWantedAmountIsReachedAndNetworkIsFull( assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(7); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactly(new ResourceAmount(A, 3)); @@ -270,18 +270,18 @@ void shouldReturnResourceToNetworkUntilWantedAmountIsReachedAndNetworkIsFull( assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(7); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactly(new ResourceAmount(A, 3)); } @Test void shouldReturnResourceToNetworkAndExportOtherResourceIfSpecified( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(B, 10, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(B, 10, Action.EXECUTE, EmptyActor.INSTANCE); exportState.setRequestedResource(1, B, 3); exportState.setCurrentlyExported(1, A, 3); @@ -291,7 +291,7 @@ void shouldReturnResourceToNetworkAndExportOtherResourceIfSpecified( assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(1); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactlyInAnyOrder( new ResourceAmount(A, 2), @@ -301,7 +301,7 @@ void shouldReturnResourceToNetworkAndExportOtherResourceIfSpecified( sut.doWork(); assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isNull(); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactlyInAnyOrder( new ResourceAmount(A, 3), @@ -312,7 +312,7 @@ void shouldReturnResourceToNetworkAndExportOtherResourceIfSpecified( assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isEqualTo(B); assertThat(exportState.getExportedAmount(1)).isEqualTo(2); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactlyInAnyOrder( new ResourceAmount(A, 3), @@ -323,7 +323,7 @@ void shouldReturnResourceToNetworkAndExportOtherResourceIfSpecified( assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isEqualTo(B); assertThat(exportState.getExportedAmount(1)).isEqualTo(3); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactlyInAnyOrder( new ResourceAmount(A, 3), @@ -336,7 +336,7 @@ void shouldReturnResourceToNetworkAndExportOtherResourceIfSpecified( assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isEqualTo(B); assertThat(exportState.getExportedAmount(1)).isEqualTo(3); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactlyInAnyOrder( new ResourceAmount(A, 3), @@ -346,11 +346,11 @@ void shouldReturnResourceToNetworkAndExportOtherResourceIfSpecified( @Test void shouldReturnResourceToNetworkAndExportOtherResourceIfSpecifiedUntilNetworkIsFull( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new LimitedStorageImpl(11)); - storageChannel.insert(B, 10, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new LimitedStorageImpl(11)); + storage.insert(B, 10, Action.EXECUTE, EmptyActor.INSTANCE); exportState.setRequestedResource(1, B, 3); exportState.setCurrentlyExported(1, A, 3); @@ -360,7 +360,7 @@ void shouldReturnResourceToNetworkAndExportOtherResourceIfSpecifiedUntilNetworkI assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(2); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactlyInAnyOrder( new ResourceAmount(A, 1), @@ -373,7 +373,7 @@ void shouldReturnResourceToNetworkAndExportOtherResourceIfSpecifiedUntilNetworkI assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(2); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactlyInAnyOrder( new ResourceAmount(A, 1), diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/externalstorage/InterfaceExternalStorageProviderImplTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/externalstorage/InterfaceExternalStorageProviderImplTest.java index 3c4425d8e..efe2a893b 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/externalstorage/InterfaceExternalStorageProviderImplTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/externalstorage/InterfaceExternalStorageProviderImplTest.java @@ -5,11 +5,11 @@ import com.refinedmods.refinedstorage2.api.network.impl.node.externalstorage.ExternalStorageProviderFactoryImpl; import com.refinedmods.refinedstorage2.api.network.impl.node.iface.InterfaceExportStateImpl; import com.refinedmods.refinedstorage2.api.network.impl.node.iface.InterfaceNetworkNode; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.storage.EmptyActor; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; -import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageChannel; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageComponent; import com.refinedmods.refinedstorage2.network.test.NetworkTest; import com.refinedmods.refinedstorage2.network.test.SetupNetwork; @@ -18,8 +18,8 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.EnumSource; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A; -import static com.refinedmods.refinedstorage2.network.test.TestResource.B; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.B; import static org.assertj.core.api.Assertions.assertThat; @NetworkTest @@ -42,7 +42,7 @@ void setUp() { @Test void shouldExposeExportedResources( - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange exportState.setCurrentlyExported(0, A, 100); @@ -56,14 +56,14 @@ void shouldExposeExportedResources( externalStorage.detectChanges(); // Assert - assertThat(networkStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( new ResourceAmount(A, 101) ); } @Test void shouldNotExposeExportedResourceWithoutExportState( - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange externalStorage.initialize(new ExternalStorageProviderFactoryImpl(new InterfaceExternalStorageProviderImpl( @@ -74,14 +74,14 @@ void shouldNotExposeExportedResourceWithoutExportState( externalStorage.detectChanges(); // Assert - assertThat(networkStorage.getAll()).isEmpty(); + assertThat(storage.getAll()).isEmpty(); } @ParameterizedTest @EnumSource(Action.class) void shouldInsertIntoInterface( final Action action, - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange externalStorage.initialize(new ExternalStorageProviderFactoryImpl(new InterfaceExternalStorageProviderImpl( @@ -89,18 +89,18 @@ void shouldInsertIntoInterface( ))); // Act - final long inserted = networkStorage.insert(A, 10, action, EmptyActor.INSTANCE); + final long inserted = storage.insert(A, 10, action, EmptyActor.INSTANCE); // Assert assertThat(inserted).isEqualTo(10); if (action == Action.EXECUTE) { - assertThat(networkStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( new ResourceAmount(A, 10) ); assertThat(exportState.getExportedResource(0)).isEqualTo(A); assertThat(exportState.getExportedAmount(0)).isEqualTo(10); } else { - assertThat(networkStorage.getAll()).isEmpty(); + assertThat(storage.getAll()).isEmpty(); assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedAmount(0)).isZero(); } @@ -110,7 +110,7 @@ void shouldInsertIntoInterface( @EnumSource(Action.class) void shouldNotInsertResourceWithoutExportState( final Action action, - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange externalStorage.initialize(new ExternalStorageProviderFactoryImpl(new InterfaceExternalStorageProviderImpl( @@ -119,18 +119,18 @@ void shouldNotInsertResourceWithoutExportState( externalStorage.detectChanges(); // Act - final long inserted = networkStorage.insert(A, 101, action, EmptyActor.INSTANCE); + final long inserted = storage.insert(A, 101, action, EmptyActor.INSTANCE); // Assert assertThat(inserted).isZero(); - assertThat(networkStorage.getAll()).isEmpty(); + assertThat(storage.getAll()).isEmpty(); } @ParameterizedTest @EnumSource(Action.class) void shouldExtractEntireResourceFromInterface( final Action action, - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange exportState.setCurrentlyExported(0, A, 50); @@ -141,18 +141,18 @@ void shouldExtractEntireResourceFromInterface( externalStorage.detectChanges(); // Act - final long extracted = networkStorage.extract(A, 101, action, EmptyActor.INSTANCE); + final long extracted = storage.extract(A, 101, action, EmptyActor.INSTANCE); // Assert assertThat(extracted).isEqualTo(100); if (action == Action.EXECUTE) { - assertThat(networkStorage.getAll()).isEmpty(); + assertThat(storage.getAll()).isEmpty(); assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedAmount(0)).isZero(); assertThat(exportState.getExportedResource(1)).isNull(); assertThat(exportState.getExportedAmount(1)).isZero(); } else { - assertThat(networkStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( new ResourceAmount(A, 100) ); assertThat(exportState.getExportedResource(0)).isEqualTo(A); @@ -166,7 +166,7 @@ void shouldExtractEntireResourceFromInterface( @EnumSource(Action.class) void shouldExtractPartialResourceFromInterface( final Action action, - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange exportState.setCurrentlyExported(0, A, 50); @@ -177,12 +177,12 @@ void shouldExtractPartialResourceFromInterface( externalStorage.detectChanges(); // Act - final long extracted = networkStorage.extract(A, 51, action, EmptyActor.INSTANCE); + final long extracted = storage.extract(A, 51, action, EmptyActor.INSTANCE); // Assert assertThat(extracted).isEqualTo(51); if (action == Action.EXECUTE) { - assertThat(networkStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( new ResourceAmount(A, 49) ); assertThat(exportState.getExportedResource(0)).isNull(); @@ -190,7 +190,7 @@ void shouldExtractPartialResourceFromInterface( assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(49); } else { - assertThat(networkStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( new ResourceAmount(A, 100) ); assertThat(exportState.getExportedResource(0)).isEqualTo(A); @@ -204,7 +204,7 @@ void shouldExtractPartialResourceFromInterface( @EnumSource(Action.class) void shouldNotExtractNonExistentResourceFromInterface( final Action action, - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange exportState.setCurrentlyExported(0, A, 50); @@ -214,11 +214,11 @@ void shouldNotExtractNonExistentResourceFromInterface( externalStorage.detectChanges(); // Act - final long extracted = networkStorage.extract(B, 1, action, EmptyActor.INSTANCE); + final long extracted = storage.extract(B, 1, action, EmptyActor.INSTANCE); // Assert assertThat(extracted).isZero(); - assertThat(networkStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( new ResourceAmount(A, 50) ); assertThat(exportState.getExportedResource(0)).isEqualTo(A); @@ -229,7 +229,7 @@ void shouldNotExtractNonExistentResourceFromInterface( @EnumSource(Action.class) void shouldNotExtractResourceWithoutExportState( final Action action, - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange externalStorage.initialize(new ExternalStorageProviderFactoryImpl(new InterfaceExternalStorageProviderImpl( @@ -238,10 +238,10 @@ void shouldNotExtractResourceWithoutExportState( externalStorage.detectChanges(); // Act - final long extracted = networkStorage.extract(A, 101, action, EmptyActor.INSTANCE); + final long extracted = storage.extract(A, 101, action, EmptyActor.INSTANCE); // Assert assertThat(extracted).isZero(); - assertThat(networkStorage.getAll()).isEmpty(); + assertThat(storage.getAll()).isEmpty(); } } diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/externalstorage/IoLoopInterfaceExternalStorageProviderImplTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/externalstorage/IoLoopInterfaceExternalStorageProviderImplTest.java index ace9aaf46..10fca42e2 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/externalstorage/IoLoopInterfaceExternalStorageProviderImplTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/externalstorage/IoLoopInterfaceExternalStorageProviderImplTest.java @@ -7,21 +7,21 @@ import com.refinedmods.refinedstorage2.api.network.impl.node.externalstorage.StorageExternalStorageProvider; import com.refinedmods.refinedstorage2.api.network.impl.node.iface.InterfaceExportStateImpl; import com.refinedmods.refinedstorage2.api.network.impl.node.iface.InterfaceNetworkNode; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.storage.EmptyActor; import com.refinedmods.refinedstorage2.api.storage.InMemoryStorageImpl; import com.refinedmods.refinedstorage2.api.storage.Storage; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; import com.refinedmods.refinedstorage2.network.test.InjectNetwork; -import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageChannel; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageComponent; import com.refinedmods.refinedstorage2.network.test.NetworkTest; import com.refinedmods.refinedstorage2.network.test.SetupNetwork; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A; import static org.assertj.core.api.Assertions.assertThat; @NetworkTest @@ -54,7 +54,7 @@ class IoLoopInterfaceExternalStorageProviderImplTest { ExternalStorageNetworkNode externalStorageWithNonInterfaceConnection; @BeforeEach - void setUp(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void setUp(@InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { interfaceWithExternalStorageState = new InterfaceExportStateImpl(2); interfaceWithExternalStorageState.setRequestedResource(1, A, 10); interfaceWithExternalStorage.setExportState(interfaceWithExternalStorageState); @@ -92,7 +92,7 @@ void setUp(@InjectNetworkStorageChannel final StorageChannel networkStorage) { // and would double count them because the External Storage update is later. @Test void shouldNotAllowInsertionByAnotherInterfaceIfThatInterfaceIsActingAsExternalStorage( - @InjectNetworkStorageChannel final StorageChannel networkStorage, + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage, @InjectNetwork final Network network ) { // Arrange @@ -121,7 +121,7 @@ void shouldNotAllowInsertionByAnotherInterfaceIfThatInterfaceIsActingAsExternalS @Test void shouldAllowInsertionByAnotherInterfaceIfThatInterfaceIsNotActingAsExternalStorage( - @InjectNetworkStorageChannel final StorageChannel networkStorage, + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage, @InjectNetwork final Network network ) { // Arrange @@ -155,7 +155,7 @@ void shouldAllowInsertionByAnotherInterfaceIfThatInterfaceIsNotActingAsExternalS // isn't allowed as it would create an extraction loop causing the Interfaces to constantly steal from each other. @Test void shouldNotAllowExtractionRequestedByAnotherInterfaceIfThatInterfaceIsActingAsExternalStorage( - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Act & assert interfaceWithExternalStorage.doWork(); @@ -193,7 +193,7 @@ void shouldNotAllowExtractionRequestedByAnotherInterfaceIfThatInterfaceIsActingA @Test void shouldAllowExtractionRequestedByAnotherInterfaceIfThatInterfaceIsNotActingAsExternalStorage( - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Act & assert interfaceWithExternalStorage.doWork(); diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/externalstorage/SelfIoInterfaceExternalStorageProviderImplTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/externalstorage/SelfIoInterfaceExternalStorageProviderImplTest.java index 1c73869e7..12e5d5f7e 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/externalstorage/SelfIoInterfaceExternalStorageProviderImplTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/externalstorage/SelfIoInterfaceExternalStorageProviderImplTest.java @@ -4,17 +4,17 @@ import com.refinedmods.refinedstorage2.api.network.impl.node.externalstorage.ExternalStorageProviderFactoryImpl; import com.refinedmods.refinedstorage2.api.network.impl.node.iface.InterfaceExportStateImpl; import com.refinedmods.refinedstorage2.api.network.impl.node.iface.InterfaceNetworkNode; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; -import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageChannel; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageComponent; import com.refinedmods.refinedstorage2.network.test.NetworkTest; import com.refinedmods.refinedstorage2.network.test.SetupNetwork; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static com.refinedmods.refinedstorage2.network.test.TestResource.B; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.B; import static org.assertj.core.api.Assertions.assertThat; @NetworkTest @@ -38,7 +38,7 @@ void setUp() { // IoLoopInterfaceExternalStorageProviderImplTest. @Test void shouldNotAllowSelfInsertionOrSelfExtraction( - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange // this would try to do a self-insert as it's an unwanted resource. diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/importer/ImporterNetworkNodeTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/importer/ImporterNetworkNodeTest.java index 03e491b57..d01189c90 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/importer/ImporterNetworkNodeTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/importer/ImporterNetworkNodeTest.java @@ -3,17 +3,17 @@ import com.refinedmods.refinedstorage2.api.core.Action; import com.refinedmods.refinedstorage2.api.network.energy.EnergyNetworkComponent; import com.refinedmods.refinedstorage2.api.network.node.importer.ImporterTransferStrategy; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.api.resource.filter.FilterMode; import com.refinedmods.refinedstorage2.api.storage.Actor; import com.refinedmods.refinedstorage2.api.storage.EmptyActor; import com.refinedmods.refinedstorage2.api.storage.InMemoryStorageImpl; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.api.storage.limited.LimitedStorageImpl; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; import com.refinedmods.refinedstorage2.network.test.InjectNetworkEnergyComponent; -import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageChannel; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageComponent; import com.refinedmods.refinedstorage2.network.test.NetworkTest; import com.refinedmods.refinedstorage2.network.test.SetupNetwork; @@ -23,11 +23,11 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A_ALTERNATIVE; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A_ALTERNATIVE2; -import static com.refinedmods.refinedstorage2.network.test.TestResource.B; -import static com.refinedmods.refinedstorage2.network.test.TestResource.C; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A_ALTERNATIVE; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A_ALTERNATIVE2; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.B; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.C; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; @@ -65,14 +65,14 @@ void shouldExtractEnergy( @Test void shouldNotWorkWithoutAnyTransferStrategy( - @InjectNetworkStorageChannel final StorageChannel storageChannel, + @InjectNetworkStorageComponent final StorageNetworkComponent storage, @InjectNetworkEnergyComponent final EnergyNetworkComponent energy ) { // Act sut.doWork(); // Assert - assertThat(storageChannel.getAll()).isEmpty(); + assertThat(storage.getAll()).isEmpty(); assertThat(energy.getStored()).isEqualTo(1000 - 5); } @@ -85,11 +85,11 @@ void shouldNotWorkWithoutNetwork() { @Test void shouldNotWorkOrExtractEnergyWithoutBeingActive( - @InjectNetworkStorageChannel final StorageChannel storageChannel, + @InjectNetworkStorageComponent final StorageNetworkComponent storage, @InjectNetworkEnergyComponent final EnergyNetworkComponent energy ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); + storage.addSource(new InMemoryStorageImpl()); final FakeImporterSource source = new FakeImporterSource(A, B) .add(A, 100) @@ -102,7 +102,7 @@ void shouldNotWorkOrExtractEnergyWithoutBeingActive( sut.doWork(); // Assert - assertThat(storageChannel.getAll()).isEmpty(); + assertThat(storage.getAll()).isEmpty(); assertThat(source.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(A, 100), new ResourceAmount(B, 100) @@ -111,9 +111,9 @@ void shouldNotWorkOrExtractEnergyWithoutBeingActive( } @Test - void testTransfer(@InjectNetworkStorageChannel final StorageChannel storageChannel) { + void testTransfer(@InjectNetworkStorageComponent final StorageNetworkComponent storage) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); + storage.addSource(new InMemoryStorageImpl()); final FakeImporterSource source = new FakeImporterSource(A, B, A) .add(A, 100) @@ -125,7 +125,7 @@ void testTransfer(@InjectNetworkStorageChannel final StorageChannel storageChann sut.doWork(); // Assert - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( new ResourceAmount(A, 1) ); assertThat(source.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( @@ -136,10 +136,10 @@ void testTransfer(@InjectNetworkStorageChannel final StorageChannel storageChann @Test void shouldUseFirstSuccessfulTransferStrategy( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); + storage.addSource(new InMemoryStorageImpl()); final FakeImporterSource emptySource = new FakeImporterSource(); final FakeImporterSource outdatedSource = new FakeImporterSource(C) @@ -161,7 +161,7 @@ void shouldUseFirstSuccessfulTransferStrategy( sut.doWork(); // Assert - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( new ResourceAmount(A, 1) ); assertThat(source.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( @@ -172,11 +172,11 @@ void shouldUseFirstSuccessfulTransferStrategy( @Test void shouldNotTransferIfThereIsNoSpaceInTheNetwork( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new LimitedStorageImpl(100)); - storageChannel.insert(C, 100, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new LimitedStorageImpl(100)); + storage.insert(C, 100, Action.EXECUTE, EmptyActor.INSTANCE); final FakeImporterSource source = new FakeImporterSource(A, B) .add(A, 100) @@ -188,7 +188,7 @@ void shouldNotTransferIfThereIsNoSpaceInTheNetwork( sut.doWork(); // Assert - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( new ResourceAmount(C, 100) ); assertThat(source.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( @@ -199,10 +199,10 @@ void shouldNotTransferIfThereIsNoSpaceInTheNetwork( @Test void testTransferDifferentResourceOverMultipleSlots( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); + storage.addSource(new InMemoryStorageImpl()); final FakeImporterSource source = new FakeImporterSource(A, B, A, B) .add(A, 11) @@ -214,7 +214,7 @@ void testTransferDifferentResourceOverMultipleSlots( sut.doWork(); // Assert - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( new ResourceAmount(A, 10) ); assertThat(source.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( @@ -225,10 +225,10 @@ void testTransferDifferentResourceOverMultipleSlots( @Test void testTransferSameResourceOverMultipleSlots( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); + storage.addSource(new InMemoryStorageImpl()); final FakeImporterSource source = new FakeImporterSource(A, A, A, B) .add(A, 20) @@ -241,7 +241,7 @@ void testTransferSameResourceOverMultipleSlots( sut.doWork(); // Assert - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( new ResourceAmount(A, 10) ); assertThat(source.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( @@ -252,10 +252,10 @@ void testTransferSameResourceOverMultipleSlots( @Test void testTransferWhereResourceIsNotAccepted( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl() { + storage.addSource(new InMemoryStorageImpl() { @Override public long insert(final ResourceKey resource, final long amount, final Action action, final Actor actor) { if (A.equals(resource)) { @@ -275,7 +275,7 @@ public long insert(final ResourceKey resource, final long amount, final Action a sut.doWork(); // Assert - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( new ResourceAmount(B, 10) ); assertThat(source.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( @@ -286,10 +286,10 @@ public long insert(final ResourceKey resource, final long amount, final Action a @Test void testTransferWithoutAnyResourcesInSource( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); + storage.addSource(new InMemoryStorageImpl()); final FakeImporterSource source = new FakeImporterSource(); final ImporterTransferStrategy strategy = new ImporterTransferStrategyImpl(source, 10); @@ -299,17 +299,17 @@ void testTransferWithoutAnyResourcesInSource( sut.doWork(); // Assert - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().isEmpty(); + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().isEmpty(); assertThat(source.getAll()).isEmpty(); } @Test - void shouldRespectAllowlist(@InjectNetworkStorageChannel final StorageChannel storageChannel) { + void shouldRespectAllowlist(@InjectNetworkStorageComponent final StorageNetworkComponent storage) { // Arrange sut.setFilterMode(FilterMode.ALLOW); sut.setFilters(Set.of(A)); - storageChannel.addSource(new InMemoryStorageImpl()); + storage.addSource(new InMemoryStorageImpl()); final FakeImporterSource source = new FakeImporterSource(B, A) .add(B, 10) @@ -322,7 +322,7 @@ void shouldRespectAllowlist(@InjectNetworkStorageChannel final StorageChannel st sut.doWork(); // Assert - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( new ResourceAmount(A, 1) ); assertThat(source.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( @@ -333,7 +333,7 @@ void shouldRespectAllowlist(@InjectNetworkStorageChannel final StorageChannel st @Test void shouldRespectAllowlistWithNormalizer( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange sut.setFilterMode(FilterMode.ALLOW); @@ -345,7 +345,7 @@ void shouldRespectAllowlistWithNormalizer( return resource; }); - storageChannel.addSource(new InMemoryStorageImpl()); + storage.addSource(new InMemoryStorageImpl()); final FakeImporterSource source = new FakeImporterSource(B, A_ALTERNATIVE, A_ALTERNATIVE2) .add(B, 10) @@ -360,7 +360,7 @@ void shouldRespectAllowlistWithNormalizer( sut.doWork(); // Assert - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(A_ALTERNATIVE, 1), new ResourceAmount(A_ALTERNATIVE2, 1) ); @@ -371,13 +371,13 @@ void shouldRespectAllowlistWithNormalizer( @Test void shouldRespectAllowlistWithoutAlternative( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange sut.setFilterMode(FilterMode.ALLOW); sut.setFilters(Set.of(A)); - storageChannel.addSource(new InMemoryStorageImpl()); + storage.addSource(new InMemoryStorageImpl()); final FakeImporterSource source = new FakeImporterSource(B) .add(B, 10); @@ -389,19 +389,19 @@ void shouldRespectAllowlistWithoutAlternative( sut.doWork(); // Assert - assertThat(storageChannel.getAll()).isEmpty(); + assertThat(storage.getAll()).isEmpty(); assertThat(source.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(B, 10) ); } @Test - void shouldRespectEmptyAllowlist(@InjectNetworkStorageChannel final StorageChannel storageChannel) { + void shouldRespectEmptyAllowlist(@InjectNetworkStorageComponent final StorageNetworkComponent storage) { // Arrange sut.setFilterMode(FilterMode.ALLOW); sut.setFilters(Set.of()); - storageChannel.addSource(new InMemoryStorageImpl()); + storage.addSource(new InMemoryStorageImpl()); final FakeImporterSource source = new FakeImporterSource(B, A) .add(B, 10) @@ -414,7 +414,7 @@ void shouldRespectEmptyAllowlist(@InjectNetworkStorageChannel final StorageChann sut.doWork(); // Assert - assertThat(storageChannel.getAll()).isEmpty(); + assertThat(storage.getAll()).isEmpty(); assertThat(source.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(B, 10), new ResourceAmount(A, 10) @@ -422,12 +422,12 @@ void shouldRespectEmptyAllowlist(@InjectNetworkStorageChannel final StorageChann } @Test - void shouldRespectBlocklist(@InjectNetworkStorageChannel final StorageChannel storageChannel) { + void shouldRespectBlocklist(@InjectNetworkStorageComponent final StorageNetworkComponent storage) { // Arrange sut.setFilterMode(FilterMode.BLOCK); sut.setFilters(Set.of(A)); - storageChannel.addSource(new InMemoryStorageImpl()); + storage.addSource(new InMemoryStorageImpl()); final FakeImporterSource source = new FakeImporterSource(A, B) .add(A, 10) @@ -440,7 +440,7 @@ void shouldRespectBlocklist(@InjectNetworkStorageChannel final StorageChannel st sut.doWork(); // Assert - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( new ResourceAmount(B, 1) ); assertThat(source.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( @@ -451,13 +451,13 @@ void shouldRespectBlocklist(@InjectNetworkStorageChannel final StorageChannel st @Test void shouldRespectBlocklistWithoutAlternative( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange sut.setFilterMode(FilterMode.BLOCK); sut.setFilters(Set.of(A)); - storageChannel.addSource(new InMemoryStorageImpl()); + storage.addSource(new InMemoryStorageImpl()); final FakeImporterSource source = new FakeImporterSource(A) .add(A, 10); @@ -469,19 +469,19 @@ void shouldRespectBlocklistWithoutAlternative( sut.doWork(); // Assert - assertThat(storageChannel.getAll()).isEmpty(); + assertThat(storage.getAll()).isEmpty(); assertThat(source.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( new ResourceAmount(A, 10) ); } @Test - void shouldRespectEmptyBlocklist(@InjectNetworkStorageChannel final StorageChannel storageChannel) { + void shouldRespectEmptyBlocklist(@InjectNetworkStorageComponent final StorageNetworkComponent storage) { // Arrange sut.setFilterMode(FilterMode.BLOCK); sut.setFilters(Set.of()); - storageChannel.addSource(new InMemoryStorageImpl()); + storage.addSource(new InMemoryStorageImpl()); final FakeImporterSource source = new FakeImporterSource(A, B) .add(A, 10) @@ -494,7 +494,7 @@ void shouldRespectEmptyBlocklist(@InjectNetworkStorageChannel final StorageChann sut.doWork(); // Assert - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( new ResourceAmount(A, 1) ); assertThat(source.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/multistorage/MultiStorageNetworkNodeTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/multistorage/MultiStorageNetworkNodeTest.java index 058500dea..3c696ab91 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/multistorage/MultiStorageNetworkNodeTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/multistorage/MultiStorageNetworkNodeTest.java @@ -2,6 +2,7 @@ import com.refinedmods.refinedstorage2.api.core.Action; import com.refinedmods.refinedstorage2.api.network.Network; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.resource.filter.FilterMode; import com.refinedmods.refinedstorage2.api.storage.AccessMode; @@ -10,15 +11,14 @@ import com.refinedmods.refinedstorage2.api.storage.StateTrackedStorage; import com.refinedmods.refinedstorage2.api.storage.Storage; import com.refinedmods.refinedstorage2.api.storage.StorageState; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.api.storage.limited.LimitedStorageImpl; import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedStorageImpl; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; import com.refinedmods.refinedstorage2.network.test.InjectNetwork; -import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageChannel; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageComponent; import com.refinedmods.refinedstorage2.network.test.NetworkTest; import com.refinedmods.refinedstorage2.network.test.SetupNetwork; -import com.refinedmods.refinedstorage2.network.test.util.FakeActor; +import com.refinedmods.refinedstorage2.network.test.fake.FakeActor; import java.util.Collection; import java.util.HashSet; @@ -30,12 +30,12 @@ import org.junit.jupiter.params.provider.EnumSource; import org.junit.jupiter.params.provider.ValueSource; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A_ALTERNATIVE; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A_ALTERNATIVE2; -import static com.refinedmods.refinedstorage2.network.test.TestResource.B; -import static com.refinedmods.refinedstorage2.network.test.TestResource.B_ALTERNATIVE; -import static com.refinedmods.refinedstorage2.network.test.TestResource.C; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A_ALTERNATIVE; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A_ALTERNATIVE2; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.B; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.B_ALTERNATIVE; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.C; import static com.refinedmods.refinedstorage2.network.test.nodefactory.AbstractNetworkNodeFactory.PROPERTY_ENERGY_USAGE; import static com.refinedmods.refinedstorage2.network.test.nodefactory.MultiStorageNetworkNodeFactory.PROPERTY_ENERGY_USAGE_PER_STORAGE; import static org.assertj.core.api.Assertions.assertThat; @@ -64,7 +64,7 @@ void setUp() { @Test void shouldInitializeButNotShowResourcesYet( - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange final Storage storage = new LimitedStorageImpl(10); @@ -82,7 +82,7 @@ void shouldInitializeButNotShowResourcesYet( @Test void shouldInitializeAndShowResourcesAfterEnabling( - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange final Storage storage = new LimitedStorageImpl(100); @@ -103,7 +103,7 @@ void shouldInitializeAndShowResourcesAfterEnabling( @Test void shouldInitializeMultipleTimes( - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange final Storage storage1 = new LimitedStorageImpl(10); @@ -127,7 +127,7 @@ void shouldInitializeMultipleTimes( } @Test - void testInitialState(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void testInitialState(@InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Assert assertThat(sut.getEnergyUsage()).isEqualTo(BASE_USAGE); assertThat(sut.getFilterMode()).isEqualTo(FilterMode.BLOCK); @@ -176,7 +176,7 @@ void testState(final boolean active) { } @Test - void shouldDetectNewStorage(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void shouldDetectNewStorage(@InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange initializeAndActivate(); @@ -195,7 +195,7 @@ void shouldDetectNewStorage(@InjectNetworkStorageChannel final StorageChannel ne } @Test - void shouldDetectChangedStorage(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void shouldDetectChangedStorage(@InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange final Storage originalStorage = new LimitedStorageImpl(10); originalStorage.insert(A, 5, Action.EXECUTE, EmptyActor.INSTANCE); @@ -223,7 +223,7 @@ void shouldDetectChangedStorage(@InjectNetworkStorageChannel final StorageChanne } @Test - void shouldDetectRemovedStorage(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void shouldDetectRemovedStorage(@InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange final Storage storage = new LimitedStorageImpl(10); storage.insert(A, 5, Action.EXECUTE, EmptyActor.INSTANCE); @@ -259,7 +259,7 @@ void shouldNotDetectStorageChangeInInvalidIndex() { @Test void shouldNotUpdateNetworkStorageWhenChangingStorageWhenInactive( - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange final Storage storage = new LimitedStorageImpl(100); @@ -282,7 +282,7 @@ void shouldNotUpdateNetworkStorageWhenChangingStorageWhenInactive( @Test void shouldHaveResourcesFromStoragePresentInNetwork( - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange final Storage storage = new LimitedStorageImpl(100); @@ -305,7 +305,7 @@ void shouldHaveResourcesFromStoragePresentInNetwork( } @Test - void shouldInsert(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void shouldInsert(@InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange final Storage storage1 = new LimitedStorageImpl(100); provider.set(1, storage1); @@ -347,7 +347,7 @@ void shouldInsert(@InjectNetworkStorageChannel final StorageChannel networkStora } @Test - void shouldExtract(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void shouldExtract(@InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange final Storage storage1 = new LimitedStorageImpl(100); storage1.insert(A, 50, Action.EXECUTE, EmptyActor.INSTANCE); @@ -392,7 +392,7 @@ void shouldExtract(@InjectNetworkStorageChannel final StorageChannel networkStor @Test void shouldRespectAllowlistWhenInserting( - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange sut.setFilterMode(FilterMode.ALLOW); @@ -415,7 +415,7 @@ void shouldRespectAllowlistWhenInserting( @Test void shouldRespectAllowlistWithNormalizerWhenInserting( - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange sut.setFilterMode(FilterMode.ALLOW); @@ -451,7 +451,7 @@ void shouldRespectAllowlistWithNormalizerWhenInserting( @Test void shouldRespectEmptyAllowlistWhenInserting( - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange sut.setFilterMode(FilterMode.ALLOW); @@ -474,7 +474,7 @@ void shouldRespectEmptyAllowlistWhenInserting( @Test void shouldRespectBlocklistWhenInserting( - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange sut.setFilterMode(FilterMode.BLOCK); @@ -497,7 +497,7 @@ void shouldRespectBlocklistWhenInserting( @Test void shouldRespectEmptyBlocklistWhenInserting( - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange sut.setFilterMode(FilterMode.BLOCK); @@ -522,7 +522,7 @@ void shouldRespectEmptyBlocklistWhenInserting( @EnumSource(AccessMode.class) void shouldRespectAccessModeWhenInserting( final AccessMode accessMode, - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange sut.setAccessMode(accessMode); @@ -545,7 +545,7 @@ void shouldRespectAccessModeWhenInserting( @EnumSource(AccessMode.class) void shouldRespectAccessModeWhenExtracting( final AccessMode accessMode, - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange sut.setAccessMode(accessMode); @@ -568,7 +568,7 @@ void shouldRespectAccessModeWhenExtracting( @Test void shouldNotAllowInsertsWhenInactive( - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange final Storage storage = new LimitedStorageImpl(100); @@ -586,7 +586,7 @@ void shouldNotAllowInsertsWhenInactive( @Test void shouldNotAllowExtractsWhenInactive( - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange final Storage storage = new LimitedStorageImpl(100); @@ -605,7 +605,7 @@ void shouldNotAllowExtractsWhenInactive( @Test void shouldHideFromNetworkWhenInactive( - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange final Storage storage = new LimitedStorageImpl(100); @@ -626,7 +626,7 @@ void shouldHideFromNetworkWhenInactive( @Test void shouldNoLongerShowOnNetworkWhenRemoved( - @InjectNetworkStorageChannel final StorageChannel networkStorage, + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage, @InjectNetwork final Network network ) { // Arrange @@ -658,7 +658,7 @@ void shouldNoLongerShowOnNetworkWhenRemoved( } @Test - void shouldTrackChanges(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void shouldTrackChanges(@InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange final Storage storage = new TrackedStorageImpl(new LimitedStorageImpl(100), () -> 0L); provider.set(1, storage); @@ -674,7 +674,7 @@ void shouldTrackChanges(@InjectNetworkStorageChannel final StorageChannel networ @Test void shouldNotifyListenerWhenStateChanges( - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange final StateTrackedStorage.Listener listener = mock(StateTrackedStorage.Listener.class); diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/multistorage/PriorityMultiStorageNetworkNodeTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/multistorage/PriorityMultiStorageNetworkNodeTest.java index 506be8cb3..baf6d15f1 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/multistorage/PriorityMultiStorageNetworkNodeTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/multistorage/PriorityMultiStorageNetworkNodeTest.java @@ -1,12 +1,12 @@ package com.refinedmods.refinedstorage2.api.network.impl.node.multistorage; import com.refinedmods.refinedstorage2.api.core.Action; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.storage.EmptyActor; import com.refinedmods.refinedstorage2.api.storage.Storage; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.api.storage.limited.LimitedStorageImpl; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; -import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageChannel; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageComponent; import com.refinedmods.refinedstorage2.network.test.NetworkTest; import com.refinedmods.refinedstorage2.network.test.SetupNetwork; @@ -14,7 +14,7 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A; import static org.assertj.core.api.Assertions.assertThat; @NetworkTest @@ -37,7 +37,7 @@ void setUp() { @ValueSource(booleans = {true, false}) void shouldRespectPriority( final boolean multiStorageAHasPriority, - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange final Storage storage1 = new LimitedStorageImpl(100); diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/relay/RelayEnergyNetworkNodeTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/relay/RelayEnergyNetworkNodeTest.java new file mode 100644 index 000000000..5992c70ef --- /dev/null +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/relay/RelayEnergyNetworkNodeTest.java @@ -0,0 +1,106 @@ +package com.refinedmods.refinedstorage2.api.network.impl.node.relay; + +import com.refinedmods.refinedstorage2.api.core.Action; +import com.refinedmods.refinedstorage2.api.network.Network; +import com.refinedmods.refinedstorage2.api.network.energy.EnergyNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.security.SecurityNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; +import com.refinedmods.refinedstorage2.api.storage.EmptyActor; +import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; +import com.refinedmods.refinedstorage2.network.test.InjectNetwork; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkEnergyComponent; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkSecurityComponent; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageComponent; +import com.refinedmods.refinedstorage2.network.test.NetworkTest; +import com.refinedmods.refinedstorage2.network.test.SetupNetwork; +import com.refinedmods.refinedstorage2.network.test.fake.FakePermissions; +import com.refinedmods.refinedstorage2.network.test.fake.FakeSecurityActors; + +import java.util.Set; + +import org.junit.jupiter.api.Test; + +import static com.refinedmods.refinedstorage2.api.network.impl.node.relay.RelayNetworkNodeTest.addSecurityPolicy; +import static com.refinedmods.refinedstorage2.api.network.impl.node.relay.RelayNetworkNodeTest.addStorageSource; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A; +import static com.refinedmods.refinedstorage2.network.test.nodefactory.AbstractNetworkNodeFactory.PROPERTY_ACTIVE; +import static org.assertj.core.api.Assertions.assertThat; + +@NetworkTest +@SetupNetwork(id = "input") +@SetupNetwork(id = "output", setupEnergy = false) +public class RelayEnergyNetworkNodeTest { + @AddNetworkNode(properties = { + @AddNetworkNode.Property(key = PROPERTY_ACTIVE, boolValue = false) + }, networkId = "input") + private RelayInputNetworkNode input; + + @AddNetworkNode(networkId = "output") + private RelayOutputNetworkNode output; + + @Test + void shouldPassEnergyComponent( + @InjectNetworkEnergyComponent(networkId = "input") final EnergyNetworkComponent inputEnergy, + @InjectNetworkSecurityComponent(networkId = "input") final SecurityNetworkComponent inputSecurity, + @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, + @InjectNetworkEnergyComponent(networkId = "output") final EnergyNetworkComponent outputEnergy, + @InjectNetworkSecurityComponent(networkId = "output") final SecurityNetworkComponent outputSecurity, + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage + ) { + // Arrange + input.setActive(true); + input.setOutputNode(output); + + addSecurityPolicy(inputSecurity, FakePermissions.OTHER); + addStorageSource(inputStorage); + + final long originalStored = inputEnergy.getStored(); + + // Act + input.setComponentTypes(Set.of(RelayComponentType.ENERGY)); + final long extracted = output.extract(10); + + // Assert + assertThat(extracted).isEqualTo(10); + assertThat(outputEnergy.getCapacity()).isEqualTo(inputEnergy.getCapacity()); + assertThat(outputEnergy.getStored()).isEqualTo(originalStored - 10); + assertThat(outputSecurity.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.A)).isTrue(); + assertThat(outputSecurity.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isFalse(); + assertThat(outputStorage.getAll()).isEmpty(); + assertThat(outputStorage.insert(A, 1, Action.EXECUTE, EmptyActor.INSTANCE)).isZero(); + assertThat(input.hasComponentType(RelayComponentType.ENERGY)).isTrue(); + assertThat(input.hasComponentType(RelayComponentType.SECURITY)).isFalse(); + assertThat(input.hasComponentType(RelayComponentType.STORAGE)).isFalse(); + } + + @Test + @SetupNetwork(id = "cycle_input", energyStored = 1, energyCapacity = 2) + @SetupNetwork(id = "cycle_input_alt", energyStored = 3, energyCapacity = 4) + void shouldDetectEnergyCycles( + @InjectNetwork("cycle_input") final Network inputNetwork, + @InjectNetworkEnergyComponent(networkId = "cycle_input") final EnergyNetworkComponent inputEnergy, + @InjectNetwork("cycle_input_alt") final Network inputAlternativeNetwork, + @InjectNetworkEnergyComponent(networkId = "cycle_input_alt") final EnergyNetworkComponent inputAlternativeEnergy + ) { + // Arrange + final RelayOutputNetworkNode cycleOutput = new RelayOutputNetworkNode(0); + cycleOutput.setEnergyDelegate(inputAlternativeEnergy); + cycleOutput.setNetwork(inputNetwork); + inputNetwork.addContainer(() -> cycleOutput); + + final RelayOutputNetworkNode cycleOutputAlternative = new RelayOutputNetworkNode(0); + cycleOutputAlternative.setEnergyDelegate(inputEnergy); + cycleOutputAlternative.setNetwork(inputAlternativeNetwork); + inputAlternativeNetwork.addContainer(() -> cycleOutputAlternative); + + // Assert + assertThat(inputEnergy.getStored()).isEqualTo(1); + assertThat(inputAlternativeEnergy.getStored()).isEqualTo(3); + + assertThat(inputEnergy.getCapacity()).isEqualTo(2); + assertThat(inputAlternativeEnergy.getCapacity()).isEqualTo(4); + + assertThat(inputEnergy.extract(10)).isEqualTo(1); + assertThat(inputAlternativeEnergy.extract(10)).isEqualTo(3); + } +} diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/relay/RelayNetworkNodeTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/relay/RelayNetworkNodeTest.java index b8397d34e..639f7baef 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/relay/RelayNetworkNodeTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/relay/RelayNetworkNodeTest.java @@ -1,32 +1,42 @@ package com.refinedmods.refinedstorage2.api.network.impl.node.relay; +import com.refinedmods.refinedstorage2.api.core.Action; import com.refinedmods.refinedstorage2.api.network.Network; import com.refinedmods.refinedstorage2.api.network.energy.EnergyNetworkComponent; import com.refinedmods.refinedstorage2.api.network.impl.security.SecurityDecisionProviderImpl; -import com.refinedmods.refinedstorage2.api.network.security.SecurityDecision; import com.refinedmods.refinedstorage2.api.network.security.SecurityNetworkComponent; import com.refinedmods.refinedstorage2.api.network.security.SecurityPolicy; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; +import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; +import com.refinedmods.refinedstorage2.api.storage.AccessMode; +import com.refinedmods.refinedstorage2.api.storage.EmptyActor; +import com.refinedmods.refinedstorage2.api.storage.InMemoryStorageImpl; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; import com.refinedmods.refinedstorage2.network.test.InjectNetwork; import com.refinedmods.refinedstorage2.network.test.InjectNetworkEnergyComponent; import com.refinedmods.refinedstorage2.network.test.InjectNetworkSecurityComponent; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageComponent; import com.refinedmods.refinedstorage2.network.test.NetworkTest; import com.refinedmods.refinedstorage2.network.test.SetupNetwork; -import com.refinedmods.refinedstorage2.network.test.util.FakePermissions; -import com.refinedmods.refinedstorage2.network.test.util.FakeSecurityActors; +import com.refinedmods.refinedstorage2.network.test.fake.FakePermissions; +import com.refinedmods.refinedstorage2.network.test.fake.FakeSecurityActors; import java.util.Set; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EnumSource; import static com.refinedmods.refinedstorage2.api.network.impl.node.security.SecurityDecisionProviderProxyNetworkNode.activeSecurityDecisionProvider; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.B; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.C; import static com.refinedmods.refinedstorage2.network.test.nodefactory.AbstractNetworkNodeFactory.PROPERTY_ACTIVE; import static com.refinedmods.refinedstorage2.network.test.nodefactory.AbstractNetworkNodeFactory.PROPERTY_ENERGY_USAGE; import static org.assertj.core.api.Assertions.assertThat; @NetworkTest @SetupNetwork(id = "input") -@SetupNetwork(id = "input_alt", energyStored = 123, energyCapacity = 456) @SetupNetwork(id = "output", setupEnergy = false) public class RelayNetworkNodeTest { private static final long INPUT_ENERGY_USAGE = 5; @@ -46,24 +56,33 @@ public class RelayNetworkNodeTest { @Test void testInitialState() { assertThat(input.getEnergyUsage()).isEqualTo(INPUT_ENERGY_USAGE); - assertThat(output.getEnergyUsage()).isEqualTo(OUTPUT_ENERGY_USAGE); + assertThat(output.getEnergyUsage()).isZero(); } @Test void shouldNotPassComponentsIfOutputNodeIsNotSet( @InjectNetworkSecurityComponent(networkId = "input") final SecurityNetworkComponent inputSecurity, + @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, @InjectNetworkEnergyComponent(networkId = "output") final EnergyNetworkComponent outputEnergy, - @InjectNetworkSecurityComponent(networkId = "output") final SecurityNetworkComponent outputSecurity + @InjectNetworkSecurityComponent(networkId = "output") final SecurityNetworkComponent outputSecurity, + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage ) { // Arrange input.setActive(true); - inputSecurity.onContainerAdded(() -> activeSecurityDecisionProvider(new SecurityDecisionProviderImpl() - .setPolicy(FakeSecurityActors.A, SecurityPolicy.of(FakePermissions.OTHER)) - )); + addSecurityPolicy(inputSecurity, FakePermissions.OTHER); + addStorageSource(inputStorage); + + input.setAccessMode(AccessMode.INSERT_EXTRACT); + input.setPriority(5); + input.setFilters(Set.of(A, B, C)); // Act - input.setComponentTypes(Set.of(RelayComponentType.ENERGY, RelayComponentType.SECURITY)); + input.setComponentTypes(Set.of( + RelayComponentType.ENERGY, + RelayComponentType.SECURITY, + RelayComponentType.STORAGE + )); // Assert assertThat(outputEnergy.getCapacity()).isZero(); @@ -71,23 +90,32 @@ void shouldNotPassComponentsIfOutputNodeIsNotSet( assertThat(outputEnergy.extract(1)).isZero(); assertThat(outputSecurity.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.A)).isTrue(); assertThat(outputSecurity.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isFalse(); + assertThat(outputStorage.getAll()).isEmpty(); + assertThat(outputStorage.insert(A, 1, Action.EXECUTE, EmptyActor.INSTANCE)).isZero(); + assertThat(outputStorage.extract(A, 1, Action.EXECUTE, EmptyActor.INSTANCE)).isZero(); + assertThat(output.getEnergyUsage()).isZero(); } @Test void shouldNotPassComponentsIfInactive( @InjectNetworkSecurityComponent(networkId = "input") final SecurityNetworkComponent inputSecurity, + @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, @InjectNetworkEnergyComponent(networkId = "output") final EnergyNetworkComponent outputEnergy, - @InjectNetworkSecurityComponent(networkId = "output") final SecurityNetworkComponent outputSecurity + @InjectNetworkSecurityComponent(networkId = "output") final SecurityNetworkComponent outputSecurity, + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage ) { // Arrange input.setOutputNode(output); - inputSecurity.onContainerAdded(() -> activeSecurityDecisionProvider(new SecurityDecisionProviderImpl() - .setPolicy(FakeSecurityActors.A, SecurityPolicy.of(FakePermissions.OTHER)) - )); + addSecurityPolicy(inputSecurity, FakePermissions.OTHER); + addStorageSource(inputStorage); // Act - input.setComponentTypes(Set.of(RelayComponentType.ENERGY, RelayComponentType.SECURITY)); + input.setComponentTypes(Set.of( + RelayComponentType.ENERGY, + RelayComponentType.SECURITY, + RelayComponentType.STORAGE + )); // Assert assertThat(outputEnergy.getCapacity()).isZero(); @@ -95,25 +123,34 @@ void shouldNotPassComponentsIfInactive( assertThat(outputEnergy.extract(1)).isZero(); assertThat(outputSecurity.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.A)).isTrue(); assertThat(outputSecurity.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isFalse(); + assertThat(outputStorage.getAll()).isEmpty(); + assertThat(outputStorage.insert(A, 1, Action.EXECUTE, EmptyActor.INSTANCE)).isZero(); + assertThat(outputStorage.extract(A, 1, Action.EXECUTE, EmptyActor.INSTANCE)).isZero(); + assertThat(output.getEnergyUsage()).isZero(); } @Test void shouldNotPassComponentsIfNoNetworkIsSet( @InjectNetworkSecurityComponent(networkId = "input") final SecurityNetworkComponent inputSecurity, + @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, @InjectNetworkEnergyComponent(networkId = "output") final EnergyNetworkComponent outputEnergy, - @InjectNetworkSecurityComponent(networkId = "output") final SecurityNetworkComponent outputSecurity + @InjectNetworkSecurityComponent(networkId = "output") final SecurityNetworkComponent outputSecurity, + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage ) { // Arrange input.setActive(true); input.setNetwork(null); input.setOutputNode(output); - inputSecurity.onContainerAdded(() -> activeSecurityDecisionProvider(new SecurityDecisionProviderImpl() - .setPolicy(FakeSecurityActors.A, SecurityPolicy.of(FakePermissions.OTHER)) - )); + addSecurityPolicy(inputSecurity, FakePermissions.OTHER); + addStorageSource(inputStorage); // Act - input.setComponentTypes(Set.of(RelayComponentType.ENERGY, RelayComponentType.SECURITY)); + input.setComponentTypes(Set.of( + RelayComponentType.ENERGY, + RelayComponentType.SECURITY, + RelayComponentType.STORAGE + )); // Assert assertThat(outputEnergy.getCapacity()).isZero(); @@ -121,23 +158,32 @@ void shouldNotPassComponentsIfNoNetworkIsSet( assertThat(outputEnergy.extract(1)).isZero(); assertThat(outputSecurity.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.A)).isTrue(); assertThat(outputSecurity.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isFalse(); + assertThat(outputStorage.getAll()).isEmpty(); + assertThat(outputStorage.insert(A, 1, Action.EXECUTE, EmptyActor.INSTANCE)).isZero(); + assertThat(outputStorage.extract(A, 1, Action.EXECUTE, EmptyActor.INSTANCE)).isZero(); + assertThat(output.getEnergyUsage()).isZero(); } @Test void shouldResetComponentsIfBecomingInactive( @InjectNetworkSecurityComponent(networkId = "input") final SecurityNetworkComponent inputSecurity, + @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, @InjectNetworkEnergyComponent(networkId = "output") final EnergyNetworkComponent outputEnergy, - @InjectNetworkSecurityComponent(networkId = "output") final SecurityNetworkComponent outputSecurity + @InjectNetworkSecurityComponent(networkId = "output") final SecurityNetworkComponent outputSecurity, + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage ) { // Arrange input.setActive(true); input.setOutputNode(output); - input.setComponentTypes(Set.of(RelayComponentType.ENERGY, RelayComponentType.SECURITY)); - - inputSecurity.onContainerAdded(() -> activeSecurityDecisionProvider(new SecurityDecisionProviderImpl() - .setPolicy(FakeSecurityActors.A, SecurityPolicy.of(FakePermissions.OTHER)) + input.setComponentTypes(Set.of( + RelayComponentType.ENERGY, + RelayComponentType.SECURITY, + RelayComponentType.STORAGE )); + addSecurityPolicy(inputSecurity, FakePermissions.OTHER); + addStorageSource(inputStorage); + // Act input.setActive(false); @@ -147,23 +193,32 @@ void shouldResetComponentsIfBecomingInactive( assertThat(outputEnergy.extract(1)).isZero(); assertThat(outputSecurity.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.A)).isTrue(); assertThat(outputSecurity.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isFalse(); + assertThat(outputStorage.getAll()).isEmpty(); + assertThat(outputStorage.insert(A, 1, Action.EXECUTE, EmptyActor.INSTANCE)).isZero(); + assertThat(outputStorage.extract(A, 1, Action.EXECUTE, EmptyActor.INSTANCE)).isZero(); + assertThat(output.getEnergyUsage()).isZero(); } @Test void shouldResetComponentsIfNetworkIsRemoved( @InjectNetworkSecurityComponent(networkId = "input") final SecurityNetworkComponent inputSecurity, + @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, @InjectNetworkEnergyComponent(networkId = "output") final EnergyNetworkComponent outputEnergy, - @InjectNetworkSecurityComponent(networkId = "output") final SecurityNetworkComponent outputSecurity + @InjectNetworkSecurityComponent(networkId = "output") final SecurityNetworkComponent outputSecurity, + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage ) { // Arrange input.setActive(true); input.setOutputNode(output); - input.setComponentTypes(Set.of(RelayComponentType.ENERGY, RelayComponentType.SECURITY)); - - inputSecurity.onContainerAdded(() -> activeSecurityDecisionProvider(new SecurityDecisionProviderImpl() - .setPolicy(FakeSecurityActors.A, SecurityPolicy.of(FakePermissions.OTHER)) + input.setComponentTypes(Set.of( + RelayComponentType.ENERGY, + RelayComponentType.SECURITY, + RelayComponentType.STORAGE )); + addSecurityPolicy(inputSecurity, FakePermissions.OTHER); + addStorageSource(inputStorage); + // Act input.setNetwork(null); @@ -173,209 +228,178 @@ void shouldResetComponentsIfNetworkIsRemoved( assertThat(outputEnergy.extract(1)).isZero(); assertThat(outputSecurity.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.A)).isTrue(); assertThat(outputSecurity.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isFalse(); + assertThat(outputStorage.getAll()).isEmpty(); + assertThat(outputStorage.insert(A, 1, Action.EXECUTE, EmptyActor.INSTANCE)).isZero(); + assertThat(outputStorage.extract(A, 1, Action.EXECUTE, EmptyActor.INSTANCE)).isZero(); + assertThat(output.getEnergyUsage()).isZero(); } @Test + @SetupNetwork(id = "input_alt", energyStored = 123, energyCapacity = 456) void shouldResetComponentsIfNetworkIsChanged( - @InjectNetwork("input_alt") final Network alternativeNetwork, - @InjectNetworkEnergyComponent(networkId = "input_alt") final EnergyNetworkComponent alternativeNetworkEnergy, - @InjectNetworkSecurityComponent(networkId = "input_alt") - final SecurityNetworkComponent alternativeNetworkSecurity - ) { - // Arrange - input.setActive(true); - input.setOutputNode(output); - input.setComponentTypes(Set.of(RelayComponentType.ENERGY, RelayComponentType.SECURITY)); - - alternativeNetworkSecurity.onContainerAdded(() -> activeSecurityDecisionProvider( - new SecurityDecisionProviderImpl() - .setPolicy(FakeSecurityActors.A, SecurityPolicy.of(FakePermissions.OTHER2)) - )); - - // Act - final long originalStored = alternativeNetworkEnergy.getStored(); - input.setNetwork(alternativeNetwork); - final long extracted = output.extract(1); - - // Assert - assertThat(output.getCapacity()).isEqualTo(alternativeNetworkEnergy.getCapacity()); - assertThat(output.getStored()).isEqualTo(originalStored - 1); - assertThat(extracted).isEqualTo(1); - assertThat(output.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.A)) - .isEqualTo(SecurityDecision.DENY); - assertThat(output.isAllowed(FakePermissions.OTHER2, FakeSecurityActors.A)) - .isEqualTo(SecurityDecision.ALLOW); - } - - @Test - void shouldPassSecurityComponent( + @InjectNetwork("input") final Network inputNetwork, @InjectNetworkSecurityComponent(networkId = "input") final SecurityNetworkComponent inputSecurity, + @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, + @InjectNetwork("input_alt") final Network inputAlternativeNetwork, + @InjectNetworkEnergyComponent(networkId = "input_alt") final EnergyNetworkComponent inputAlternativeEnergy, + @InjectNetworkSecurityComponent(networkId = "input_alt") + final SecurityNetworkComponent inputAlternativeSecurity, + @InjectNetworkStorageComponent(networkId = "input_alt") final StorageNetworkComponent inputAlternativeStorage, @InjectNetworkEnergyComponent(networkId = "output") final EnergyNetworkComponent outputEnergy, - @InjectNetworkSecurityComponent(networkId = "output") final SecurityNetworkComponent outputSecurity + @InjectNetworkSecurityComponent(networkId = "output") final SecurityNetworkComponent outputSecurity, + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage ) { // Arrange input.setActive(true); input.setOutputNode(output); - - inputSecurity.onContainerAdded(() -> activeSecurityDecisionProvider( - new SecurityDecisionProviderImpl() - .setPolicy(FakeSecurityActors.A, SecurityPolicy.of(FakePermissions.ALLOW_BY_DEFAULT)) - .setPolicy(FakeSecurityActors.B, SecurityPolicy.of(FakePermissions.OTHER)) + input.setComponentTypes(Set.of( + RelayComponentType.ENERGY, + RelayComponentType.SECURITY, + RelayComponentType.STORAGE )); - // Act - input.setComponentTypes(Set.of(RelayComponentType.SECURITY)); + inputStorage.addSource(new InMemoryStorageImpl()); + inputStorage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); + inputStorage.insert(B, 5, Action.EXECUTE, EmptyActor.INSTANCE); + inputStorage.extract(B, 3, Action.EXECUTE, EmptyActor.INSTANCE); - // Assert - assertThat(outputEnergy.getCapacity()).isZero(); - assertThat(outputEnergy.getStored()).isZero(); - assertThat(outputEnergy.extract(1)).isZero(); - assertThat(outputSecurity.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.A)).isTrue(); - assertThat(outputSecurity.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.B)).isFalse(); - assertThat(outputSecurity.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isFalse(); - assertThat(outputSecurity.isAllowed(FakePermissions.OTHER, FakeSecurityActors.B)).isTrue(); - } + inputAlternativeStorage.addSource(new InMemoryStorageImpl()); + inputAlternativeStorage.insert(A, 33, Action.EXECUTE, EmptyActor.INSTANCE); - @Test - void shouldNotActAsSecurityDecisionProviderIfOutputIsDisabled( - @InjectNetworkSecurityComponent(networkId = "input") final SecurityNetworkComponent inputSecurity, - @InjectNetworkSecurityComponent(networkId = "output") final SecurityNetworkComponent outputSecurity - ) { - // Arrange - input.setActive(true); - input.setOutputNode(output); + addSecurityPolicy(inputSecurity, FakePermissions.OTHER); + addSecurityPolicy(inputAlternativeSecurity, FakePermissions.OTHER2); - inputSecurity.onContainerAdded(() -> activeSecurityDecisionProvider(new SecurityDecisionProviderImpl() - .setPolicy(FakeSecurityActors.A, SecurityPolicy.of(FakePermissions.OTHER)) - )); + // Act + inputNetwork.removeContainer(() -> input); + input.setNetwork(inputAlternativeNetwork); + inputAlternativeNetwork.addContainer(() -> input); - input.setComponentTypes(Set.of(RelayComponentType.SECURITY)); + final long originalStored = inputAlternativeEnergy.getStored(); + final long extractedEnergy = output.extract(1); - // Act - output.setActive(false); + final long insertedStorage = outputStorage.insert(C, 1, Action.EXECUTE, EmptyActor.INSTANCE); + final long extractedStorage = outputStorage.extract(A, 1, Action.EXECUTE, EmptyActor.INSTANCE); // Assert - assertThat(outputSecurity.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.A)).isTrue(); + assertThat(extractedEnergy).isEqualTo(1); + assertThat(insertedStorage).isEqualTo(1); + assertThat(extractedStorage).isEqualTo(1); + + assertThat(outputEnergy.getCapacity()).isEqualTo(inputAlternativeEnergy.getCapacity()); + assertThat(outputEnergy.getStored()).isEqualTo(originalStored - 1); + assertThat(outputSecurity.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.A)).isFalse(); assertThat(outputSecurity.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isFalse(); + assertThat(outputSecurity.isAllowed(FakePermissions.OTHER2, FakeSecurityActors.A)).isTrue(); + assertThat(outputStorage.getStored()).isEqualTo(33); + assertThat(outputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + new ResourceAmount(A, 32), + new ResourceAmount(C, 1) + ); + assertThat(inputAlternativeStorage.getAll()).usingRecursiveFieldByFieldElementComparator() + .containsExactlyInAnyOrder(new ResourceAmount(A, 32), new ResourceAmount(C, 1)); + assertThat(inputStorage.getAll()).usingRecursiveFieldByFieldElementComparator() + .containsExactlyInAnyOrder(new ResourceAmount(A, 10), new ResourceAmount(B, 2)); + assertThat(output.getEnergyUsage()).isEqualTo(OUTPUT_ENERGY_USAGE); } @Test - void shouldNotActAsSecurityDecisionProviderIfSecurityIsNotPassed( + void shouldResetComponentsWhenComponentTypeIsEnabled( + @InjectNetworkEnergyComponent(networkId = "input") final EnergyNetworkComponent inputEnergy, @InjectNetworkSecurityComponent(networkId = "input") final SecurityNetworkComponent inputSecurity, - @InjectNetworkSecurityComponent(networkId = "output") final SecurityNetworkComponent outputSecurity + @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, + @InjectNetworkEnergyComponent(networkId = "output") final EnergyNetworkComponent outputEnergy, + @InjectNetworkSecurityComponent(networkId = "output") final SecurityNetworkComponent outputSecurity, + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage ) { // Arrange input.setActive(true); input.setOutputNode(output); - - inputSecurity.onContainerAdded(() -> activeSecurityDecisionProvider(new SecurityDecisionProviderImpl() - .setPolicy(FakeSecurityActors.A, SecurityPolicy.of(FakePermissions.OTHER)) + input.setComponentTypes(Set.of( + RelayComponentType.SECURITY, + RelayComponentType.STORAGE )); - // Act - input.setComponentTypes(Set.of()); - - // Assert - assertThat(outputSecurity.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.A)).isTrue(); - assertThat(outputSecurity.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isFalse(); - } + addSecurityPolicy(inputSecurity, FakePermissions.OTHER); + addStorageSource(inputStorage); - @Test - @SetupNetwork(id = "cycle_input") - @SetupNetwork(id = "cycle_input_alt") - void shouldDetectSecurityCycles( - @InjectNetwork("cycle_input") final Network inputNetwork, - @InjectNetworkSecurityComponent(networkId = "cycle_input") final SecurityNetworkComponent inputSecurity, - @InjectNetwork("cycle_input_alt") final Network inputAlternativeNetwork, - @InjectNetworkSecurityComponent(networkId = "cycle_input_alt") - final SecurityNetworkComponent inputAlternativeSecurity - ) { - // Arrange - inputSecurity.onContainerAdded(() -> activeSecurityDecisionProvider( - new SecurityDecisionProviderImpl() - .setPolicy(FakeSecurityActors.A, SecurityPolicy.of(FakePermissions.OTHER)) - )); - - inputAlternativeSecurity.onContainerAdded(() -> activeSecurityDecisionProvider( - new SecurityDecisionProviderImpl() - .setPolicy(FakeSecurityActors.A, SecurityPolicy.of(FakePermissions.OTHER2)) - )); - - final RelayOutputNetworkNode cycleOutput = new RelayOutputNetworkNode(0); - cycleOutput.setSecurityDelegate(inputAlternativeSecurity); - cycleOutput.setNetwork(inputNetwork); - inputNetwork.addContainer(() -> cycleOutput); - - final RelayOutputNetworkNode cycleOutputAlternative = new RelayOutputNetworkNode(0); - cycleOutputAlternative.setSecurityDelegate(inputSecurity); - cycleOutputAlternative.setNetwork(inputAlternativeNetwork); - inputAlternativeNetwork.addContainer(() -> cycleOutputAlternative); + // Act + final long originalStored = inputEnergy.getStored(); + input.updateComponentType(RelayComponentType.ENERGY, true); + final long extracted = output.extract(10); // Assert - assertThat(inputSecurity.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isTrue(); - assertThat(inputSecurity.isAllowed(FakePermissions.OTHER2, FakeSecurityActors.A)).isFalse(); - - assertThat(inputAlternativeSecurity.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isFalse(); - assertThat(inputAlternativeSecurity.isAllowed(FakePermissions.OTHER2, FakeSecurityActors.A)).isTrue(); + assertThat(outputEnergy.getCapacity()).isEqualTo(inputEnergy.getCapacity()); + assertThat(outputEnergy.getStored()).isEqualTo(originalStored - 10); + assertThat(extracted).isEqualTo(10); + assertThat(outputSecurity.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.A)).isFalse(); + assertThat(outputSecurity.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isTrue(); + assertThat(outputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + new ResourceAmount(A, 10) + ); + assertThat(outputStorage.insert(A, 1, Action.EXECUTE, EmptyActor.INSTANCE)).isEqualTo(1); + assertThat(outputStorage.extract(A, 1, Action.EXECUTE, EmptyActor.INSTANCE)).isEqualTo(1); + assertThat(output.getEnergyUsage()).isEqualTo(OUTPUT_ENERGY_USAGE); } @Test - void shouldPassEnergyComponent( - @InjectNetworkEnergyComponent(networkId = "input") final EnergyNetworkComponent inputEnergy, + void shouldResetComponentsWhenComponentTypeIsDisabled( @InjectNetworkSecurityComponent(networkId = "input") final SecurityNetworkComponent inputSecurity, + @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, @InjectNetworkEnergyComponent(networkId = "output") final EnergyNetworkComponent outputEnergy, - @InjectNetworkSecurityComponent(networkId = "output") final SecurityNetworkComponent outputSecurity + @InjectNetworkSecurityComponent(networkId = "output") final SecurityNetworkComponent outputSecurity, + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage ) { // Arrange input.setActive(true); input.setOutputNode(output); - - inputSecurity.onContainerAdded(() -> activeSecurityDecisionProvider(new SecurityDecisionProviderImpl() - .setPolicy(FakeSecurityActors.A, SecurityPolicy.of(FakePermissions.OTHER)) + input.setComponentTypes(Set.of( + RelayComponentType.SECURITY, + RelayComponentType.STORAGE )); - final long originalStored = inputEnergy.getStored(); + addSecurityPolicy(inputSecurity, FakePermissions.OTHER); + addStorageSource(inputStorage); // Act - input.setComponentTypes(Set.of(RelayComponentType.ENERGY)); + input.updateComponentType(RelayComponentType.ENERGY, false); final long extracted = output.extract(10); // Assert - assertThat(extracted).isEqualTo(10); - assertThat(outputEnergy.getCapacity()).isEqualTo(inputEnergy.getCapacity()); - assertThat(outputEnergy.getStored()).isEqualTo(originalStored - 10); - assertThat(outputSecurity.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.A)).isTrue(); - assertThat(outputSecurity.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isFalse(); + assertThat(outputEnergy.getCapacity()).isZero(); + assertThat(outputEnergy.getStored()).isZero(); + assertThat(extracted).isZero(); + assertThat(outputSecurity.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.A)).isFalse(); + assertThat(outputSecurity.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isTrue(); + assertThat(outputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + new ResourceAmount(A, 10) + ); + assertThat(outputStorage.insert(A, 1, Action.EXECUTE, EmptyActor.INSTANCE)).isEqualTo(1); + assertThat(outputStorage.extract(A, 1, Action.EXECUTE, EmptyActor.INSTANCE)).isEqualTo(1); + assertThat(output.getEnergyUsage()).isEqualTo(OUTPUT_ENERGY_USAGE); } - @Test - @SetupNetwork(id = "cycle_input", energyStored = 1, energyCapacity = 2) - @SetupNetwork(id = "cycle_input_alt", energyStored = 3, energyCapacity = 4) - void shouldDetectEnergyCycles( - @InjectNetwork("cycle_input") final Network inputNetwork, - @InjectNetworkEnergyComponent(networkId = "cycle_input") final EnergyNetworkComponent inputEnergy, - @InjectNetwork("cycle_input_alt") final Network inputAlternativeNetwork, - @InjectNetworkEnergyComponent(networkId = "cycle_input_alt") final EnergyNetworkComponent inputAlternativeEnergy - ) { + @ParameterizedTest + @EnumSource(RelayComponentType.class) + void shouldUseEnergyWhenAtLeastOneComponentIsActive(final RelayComponentType type) { // Arrange - final RelayOutputNetworkNode cycleOutput = new RelayOutputNetworkNode(0); - cycleOutput.setEnergyDelegate(inputAlternativeEnergy); - cycleOutput.setNetwork(inputNetwork); - inputNetwork.addContainer(() -> cycleOutput); + input.setActive(true); + input.setOutputNode(output); - final RelayOutputNetworkNode cycleOutputAlternative = new RelayOutputNetworkNode(0); - cycleOutputAlternative.setEnergyDelegate(inputEnergy); - cycleOutputAlternative.setNetwork(inputAlternativeNetwork); - inputAlternativeNetwork.addContainer(() -> cycleOutputAlternative); + // Act + input.setComponentTypes(Set.of(type)); // Assert - assertThat(inputEnergy.getStored()).isEqualTo(1); - assertThat(inputAlternativeEnergy.getStored()).isEqualTo(3); + assertThat(output.getEnergyUsage()).isEqualTo(OUTPUT_ENERGY_USAGE); + } - assertThat(inputEnergy.getCapacity()).isEqualTo(2); - assertThat(inputAlternativeEnergy.getCapacity()).isEqualTo(4); + static void addSecurityPolicy(final SecurityNetworkComponent security, final FakePermissions permission) { + security.onContainerAdded(() -> activeSecurityDecisionProvider(new SecurityDecisionProviderImpl() + .setPolicy(FakeSecurityActors.A, SecurityPolicy.of(permission)) + )); + } - assertThat(inputEnergy.extract(10)).isEqualTo(1); - assertThat(inputAlternativeEnergy.extract(10)).isEqualTo(3); + static void addStorageSource(final StorageNetworkComponent storage) { + storage.addSource(new InMemoryStorageImpl()); + storage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); } } diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/relay/RelaySecurityNetworkNodeTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/relay/RelaySecurityNetworkNodeTest.java new file mode 100644 index 000000000..8ed190fbe --- /dev/null +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/relay/RelaySecurityNetworkNodeTest.java @@ -0,0 +1,165 @@ +package com.refinedmods.refinedstorage2.api.network.impl.node.relay; + +import com.refinedmods.refinedstorage2.api.core.Action; +import com.refinedmods.refinedstorage2.api.network.Network; +import com.refinedmods.refinedstorage2.api.network.energy.EnergyNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.impl.security.SecurityDecisionProviderImpl; +import com.refinedmods.refinedstorage2.api.network.security.SecurityNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.security.SecurityPolicy; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; +import com.refinedmods.refinedstorage2.api.storage.EmptyActor; +import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; +import com.refinedmods.refinedstorage2.network.test.InjectNetwork; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkEnergyComponent; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkSecurityComponent; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageComponent; +import com.refinedmods.refinedstorage2.network.test.NetworkTest; +import com.refinedmods.refinedstorage2.network.test.SetupNetwork; +import com.refinedmods.refinedstorage2.network.test.fake.FakePermissions; +import com.refinedmods.refinedstorage2.network.test.fake.FakeSecurityActors; + +import java.util.Set; + +import org.junit.jupiter.api.Test; + +import static com.refinedmods.refinedstorage2.api.network.impl.node.relay.RelayNetworkNodeTest.addStorageSource; +import static com.refinedmods.refinedstorage2.api.network.impl.node.security.SecurityDecisionProviderProxyNetworkNode.activeSecurityDecisionProvider; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A; +import static com.refinedmods.refinedstorage2.network.test.nodefactory.AbstractNetworkNodeFactory.PROPERTY_ACTIVE; +import static org.assertj.core.api.Assertions.assertThat; + +@NetworkTest +@SetupNetwork(id = "input") +@SetupNetwork(id = "output", setupEnergy = false) +public class RelaySecurityNetworkNodeTest { + @AddNetworkNode(properties = { + @AddNetworkNode.Property(key = PROPERTY_ACTIVE, boolValue = false) + }, networkId = "input") + private RelayInputNetworkNode input; + + @AddNetworkNode(networkId = "output") + private RelayOutputNetworkNode output; + + @Test + void shouldPassSecurityComponent( + @InjectNetworkSecurityComponent(networkId = "input") final SecurityNetworkComponent inputSecurity, + @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, + @InjectNetworkEnergyComponent(networkId = "output") final EnergyNetworkComponent outputEnergy, + @InjectNetworkSecurityComponent(networkId = "output") final SecurityNetworkComponent outputSecurity, + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage + ) { + // Arrange + input.setActive(true); + input.setOutputNode(output); + + inputSecurity.onContainerAdded(() -> activeSecurityDecisionProvider( + new SecurityDecisionProviderImpl() + .setPolicy(FakeSecurityActors.A, SecurityPolicy.of(FakePermissions.ALLOW_BY_DEFAULT)) + .setPolicy(FakeSecurityActors.B, SecurityPolicy.of(FakePermissions.OTHER)) + )); + + addStorageSource(inputStorage); + + // Act + input.setComponentTypes(Set.of(RelayComponentType.SECURITY)); + + // Assert + assertThat(outputEnergy.getCapacity()).isZero(); + assertThat(outputEnergy.getStored()).isZero(); + assertThat(outputEnergy.extract(1)).isZero(); + assertThat(outputSecurity.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.A)).isTrue(); + assertThat(outputSecurity.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.B)).isFalse(); + assertThat(outputSecurity.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isFalse(); + assertThat(outputSecurity.isAllowed(FakePermissions.OTHER, FakeSecurityActors.B)).isTrue(); + assertThat(outputStorage.getAll()).isEmpty(); + assertThat(outputStorage.insert(A, 1, Action.EXECUTE, EmptyActor.INSTANCE)).isZero(); + assertThat(outputStorage.extract(A, 1, Action.EXECUTE, EmptyActor.INSTANCE)).isZero(); + assertThat(input.hasComponentType(RelayComponentType.ENERGY)).isFalse(); + assertThat(input.hasComponentType(RelayComponentType.SECURITY)).isTrue(); + assertThat(input.hasComponentType(RelayComponentType.STORAGE)).isFalse(); + } + + @Test + void shouldNotActAsSecurityDecisionProviderIfOutputIsDisabled( + @InjectNetworkSecurityComponent(networkId = "input") final SecurityNetworkComponent inputSecurity, + @InjectNetworkSecurityComponent(networkId = "output") final SecurityNetworkComponent outputSecurity + ) { + // Arrange + input.setActive(true); + input.setOutputNode(output); + + inputSecurity.onContainerAdded(() -> activeSecurityDecisionProvider(new SecurityDecisionProviderImpl() + .setPolicy(FakeSecurityActors.A, SecurityPolicy.of(FakePermissions.OTHER)) + )); + + input.setComponentTypes(Set.of(RelayComponentType.SECURITY)); + + // Act + output.setActive(false); + + // Assert + assertThat(outputSecurity.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.A)).isTrue(); + assertThat(outputSecurity.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isFalse(); + } + + @Test + void shouldNotActAsSecurityDecisionProviderIfSecurityIsNotPassed( + @InjectNetworkSecurityComponent(networkId = "input") final SecurityNetworkComponent inputSecurity, + @InjectNetworkSecurityComponent(networkId = "output") final SecurityNetworkComponent outputSecurity + ) { + // Arrange + input.setActive(true); + input.setOutputNode(output); + + inputSecurity.onContainerAdded(() -> activeSecurityDecisionProvider(new SecurityDecisionProviderImpl() + .setPolicy(FakeSecurityActors.A, SecurityPolicy.of(FakePermissions.OTHER)) + )); + + // Act + input.setComponentTypes(Set.of()); + + // Assert + assertThat(outputSecurity.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.A)).isTrue(); + assertThat(outputSecurity.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isFalse(); + } + + @Test + @SetupNetwork(id = "cycle_input") + @SetupNetwork(id = "cycle_input_alt") + void shouldDetectSecurityCycles( + @InjectNetwork("cycle_input") final Network inputNetwork, + @InjectNetworkSecurityComponent(networkId = "cycle_input") final SecurityNetworkComponent inputSecurity, + @InjectNetwork("cycle_input_alt") final Network inputAlternativeNetwork, + @InjectNetworkSecurityComponent(networkId = "cycle_input_alt") + final SecurityNetworkComponent inputAlternativeSecurity + ) { + // Arrange + inputSecurity.onContainerAdded(() -> activeSecurityDecisionProvider( + new SecurityDecisionProviderImpl() + .setPolicy(FakeSecurityActors.A, SecurityPolicy.of(FakePermissions.OTHER)) + )); + + inputAlternativeSecurity.onContainerAdded(() -> activeSecurityDecisionProvider( + new SecurityDecisionProviderImpl() + .setPolicy(FakeSecurityActors.A, SecurityPolicy.of(FakePermissions.OTHER2)) + )); + + // Act + final RelayOutputNetworkNode cycleOutput = new RelayOutputNetworkNode(0); + cycleOutput.setSecurityDelegate(inputAlternativeSecurity); + cycleOutput.setNetwork(inputNetwork); + inputNetwork.addContainer(() -> cycleOutput); + + final RelayOutputNetworkNode cycleOutputAlternative = new RelayOutputNetworkNode(0); + cycleOutputAlternative.setSecurityDelegate(inputSecurity); + cycleOutputAlternative.setNetwork(inputAlternativeNetwork); + inputAlternativeNetwork.addContainer(() -> cycleOutputAlternative); + + // Assert + assertThat(inputSecurity.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isTrue(); + assertThat(inputSecurity.isAllowed(FakePermissions.OTHER2, FakeSecurityActors.A)).isFalse(); + + assertThat(inputAlternativeSecurity.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isFalse(); + assertThat(inputAlternativeSecurity.isAllowed(FakePermissions.OTHER2, FakeSecurityActors.A)).isTrue(); + } +} diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/relay/RelayStorageNetworkNodeTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/relay/RelayStorageNetworkNodeTest.java new file mode 100644 index 000000000..13bfe552e --- /dev/null +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/relay/RelayStorageNetworkNodeTest.java @@ -0,0 +1,634 @@ +package com.refinedmods.refinedstorage2.api.network.impl.node.relay; + +import com.refinedmods.refinedstorage2.api.core.Action; +import com.refinedmods.refinedstorage2.api.network.Network; +import com.refinedmods.refinedstorage2.api.network.energy.EnergyNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.security.SecurityNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; +import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; +import com.refinedmods.refinedstorage2.api.resource.filter.FilterMode; +import com.refinedmods.refinedstorage2.api.storage.AccessMode; +import com.refinedmods.refinedstorage2.api.storage.EmptyActor; +import com.refinedmods.refinedstorage2.api.storage.InMemoryStorageImpl; +import com.refinedmods.refinedstorage2.api.storage.Storage; +import com.refinedmods.refinedstorage2.api.storage.composite.PriorityStorage; +import com.refinedmods.refinedstorage2.api.storage.limited.LimitedStorageImpl; +import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; +import com.refinedmods.refinedstorage2.network.test.InjectNetwork; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkEnergyComponent; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkSecurityComponent; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageComponent; +import com.refinedmods.refinedstorage2.network.test.NetworkTest; +import com.refinedmods.refinedstorage2.network.test.SetupNetwork; +import com.refinedmods.refinedstorage2.network.test.fake.FakePermissions; +import com.refinedmods.refinedstorage2.network.test.fake.FakeSecurityActors; + +import java.util.Set; + +import org.junit.jupiter.api.Test; + +import static com.refinedmods.refinedstorage2.api.network.impl.node.relay.RelayNetworkNodeTest.addSecurityPolicy; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A_ALTERNATIVE; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.B; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.C; +import static com.refinedmods.refinedstorage2.network.test.nodefactory.AbstractNetworkNodeFactory.PROPERTY_ACTIVE; +import static org.assertj.core.api.Assertions.assertThat; + +@NetworkTest +@SetupNetwork(id = "input") +@SetupNetwork(id = "output", setupEnergy = false) +public class RelayStorageNetworkNodeTest { + @AddNetworkNode(properties = { + @AddNetworkNode.Property(key = PROPERTY_ACTIVE, boolValue = false) + }, networkId = "input") + private RelayInputNetworkNode input; + + @AddNetworkNode(networkId = "output") + private RelayOutputNetworkNode output; + + @Test + void shouldPassStorageComponent( + @InjectNetworkSecurityComponent(networkId = "input") final SecurityNetworkComponent inputSecurity, + @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, + @InjectNetworkEnergyComponent(networkId = "output") final EnergyNetworkComponent outputEnergy, + @InjectNetworkSecurityComponent(networkId = "output") final SecurityNetworkComponent outputSecurity, + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage + ) { + // Arrange + input.setActive(true); + input.setOutputNode(output); + + addSecurityPolicy(inputSecurity, FakePermissions.OTHER); + + inputStorage.addSource(new InMemoryStorageImpl()); + inputStorage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); + + // Act + input.setComponentTypes(Set.of(RelayComponentType.STORAGE)); + + inputStorage.insert(B, 5, Action.EXECUTE, EmptyActor.INSTANCE); + inputStorage.extract(B, 3, Action.EXECUTE, EmptyActor.INSTANCE); + + // Assert + assertThat(outputEnergy.getCapacity()).isZero(); + assertThat(outputEnergy.getStored()).isZero(); + assertThat(outputSecurity.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.A)).isTrue(); + assertThat(outputSecurity.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isFalse(); + + assertThat(inputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + new ResourceAmount(A, 10), + new ResourceAmount(B, 2) + ); + assertThat(outputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + new ResourceAmount(A, 10), + new ResourceAmount(B, 2) + ); + assertThat(outputStorage.getStored()).isEqualTo(12); + assertThat(input.hasComponentType(RelayComponentType.ENERGY)).isFalse(); + assertThat(input.hasComponentType(RelayComponentType.SECURITY)).isFalse(); + assertThat(input.hasComponentType(RelayComponentType.STORAGE)).isTrue(); + } + + @Test + void shouldRemoveStorageWhenNetworkIsRemoved( + @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage + ) { + // Arrange + input.setActive(true); + input.setOutputNode(output); + + inputStorage.addSource(new InMemoryStorageImpl()); + inputStorage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); + input.setComponentTypes(Set.of(RelayComponentType.STORAGE)); + inputStorage.insert(B, 5, Action.EXECUTE, EmptyActor.INSTANCE); + inputStorage.extract(B, 3, Action.EXECUTE, EmptyActor.INSTANCE); + + // Act + input.setNetwork(null); + + inputStorage.insert(C, 1, Action.EXECUTE, EmptyActor.INSTANCE); + + // Assert + assertThat(inputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + new ResourceAmount(A, 10), + new ResourceAmount(B, 2), + new ResourceAmount(C, 1) + ); + assertThat(outputStorage.getAll()).isEmpty(); + assertThat(outputStorage.getStored()).isZero(); + assertThat(outputStorage.insert(A, 1, Action.EXECUTE, EmptyActor.INSTANCE)).isZero(); + assertThat(outputStorage.extract(A, 1, Action.EXECUTE, EmptyActor.INSTANCE)).isZero(); + } + + @Test + @SetupNetwork(id = "output_alt") + void shouldNotNotifyOldOutputNetworkWhenOutputNetworkHasChanged( + @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, + @InjectNetwork("output") final Network outputNetwork, + @InjectNetworkStorageComponent(networkId = "output_alt") final StorageNetworkComponent outputAlternativeStorage, + @InjectNetwork("output_alt") final Network outputAlternativeNetwork, + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage + ) { + // Arrange + input.setActive(true); + input.setOutputNode(output); + + inputStorage.addSource(new InMemoryStorageImpl()); + inputStorage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); + input.setComponentTypes(Set.of(RelayComponentType.STORAGE)); + + // Act + outputNetwork.removeContainer(() -> output); + outputAlternativeNetwork.addContainer(() -> output); + output.setNetwork(outputAlternativeNetwork); + + inputStorage.insert(A, 1, Action.EXECUTE, EmptyActor.INSTANCE); + + // Assert + assertThat(outputAlternativeStorage.getAll()).usingRecursiveFieldByFieldElementComparator() + .containsExactlyInAnyOrder(new ResourceAmount(A, 11)); + assertThat(outputAlternativeStorage.getStored()).isEqualTo(11); + assertThat(outputStorage.getAll()).isEmpty(); + assertThat(outputStorage.getStored()).isZero(); + } + + @Test + void shouldInsertResourcesIntoInputStorageFromOutputStorage( + @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage + ) { + // Arrange + input.setActive(true); + input.setOutputNode(output); + input.setComponentTypes(Set.of(RelayComponentType.STORAGE)); + + inputStorage.addSource(new InMemoryStorageImpl()); + inputStorage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); + + // Act + final long inserted = outputStorage.insert(B, 2, Action.EXECUTE, EmptyActor.INSTANCE); + + // Assert + assertThat(inserted).isEqualTo(2); + assertThat(inputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + new ResourceAmount(A, 10), + new ResourceAmount(B, 2) + ); + assertThat(inputStorage.getStored()).isEqualTo(12); + assertThat(outputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + new ResourceAmount(A, 10), + new ResourceAmount(B, 2) + ); + assertThat(outputStorage.getStored()).isEqualTo(12); + } + + @Test + void shouldExtractResourcesFromInputStorageIntoOutputStorage( + @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage + ) { + // Arrange + input.setActive(true); + input.setOutputNode(output); + input.setComponentTypes(Set.of(RelayComponentType.STORAGE)); + + inputStorage.addSource(new InMemoryStorageImpl()); + inputStorage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); + + // Act + final long extracted = outputStorage.extract(A, 2, Action.EXECUTE, EmptyActor.INSTANCE); + + // Assert + assertThat(extracted).isEqualTo(2); + assertThat(inputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + new ResourceAmount(A, 8) + ); + assertThat(inputStorage.getStored()).isEqualTo(8); + assertThat(outputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + new ResourceAmount(A, 8) + ); + assertThat(outputStorage.getStored()).isEqualTo(8); + } + + @Test + void shouldNotInsertInExtractOnlyMode( + @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage + ) { + // Arrange + input.setActive(true); + input.setOutputNode(output); + input.setAccessMode(AccessMode.EXTRACT); + input.setComponentTypes(Set.of(RelayComponentType.STORAGE)); + + inputStorage.addSource(new InMemoryStorageImpl()); + inputStorage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); + + // Act + final long inserted = outputStorage.insert(B, 2, Action.EXECUTE, EmptyActor.INSTANCE); + final long extracted = outputStorage.extract(A, 2, Action.EXECUTE, EmptyActor.INSTANCE); + + // Assert + assertThat(inserted).isZero(); + assertThat(extracted).isEqualTo(2); + assertThat(inputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + new ResourceAmount(A, 8) + ); + assertThat(inputStorage.getStored()).isEqualTo(8); + assertThat(outputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + new ResourceAmount(A, 8) + ); + assertThat(outputStorage.getStored()).isEqualTo(8); + } + + @Test + void shouldNotExtractInInsertOnlyMode( + @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage + ) { + // Arrange + input.setActive(true); + input.setOutputNode(output); + input.setAccessMode(AccessMode.INSERT); + input.setComponentTypes(Set.of(RelayComponentType.STORAGE)); + + inputStorage.addSource(new InMemoryStorageImpl()); + inputStorage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); + + // Act + final long inserted = outputStorage.insert(B, 2, Action.EXECUTE, EmptyActor.INSTANCE); + final long extracted = outputStorage.extract(A, 2, Action.EXECUTE, EmptyActor.INSTANCE); + + // Assert + assertThat(inserted).isEqualTo(2); + assertThat(extracted).isZero(); + assertThat(inputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + new ResourceAmount(A, 10), + new ResourceAmount(B, 2) + ); + assertThat(inputStorage.getStored()).isEqualTo(12); + assertThat(outputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + new ResourceAmount(A, 10), + new ResourceAmount(B, 2) + ); + assertThat(outputStorage.getStored()).isEqualTo(12); + } + + @Test + void shouldRespectPriorityOfOutput( + @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage + ) { + // Arrange + input.setActive(true); + input.setOutputNode(output); + input.setPriority(3); + input.setComponentTypes(Set.of(RelayComponentType.STORAGE)); + inputStorage.addSource(new InMemoryStorageImpl()); + inputStorage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); + + final Storage fallbackStorage1 = PriorityStorage.of(new InMemoryStorageImpl(), 2); + fallbackStorage1.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); + outputStorage.addSource(fallbackStorage1); + + final Storage fallbackStorage2 = PriorityStorage.of(new InMemoryStorageImpl(), 1); + fallbackStorage2.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); + outputStorage.addSource(fallbackStorage2); + + // Act + final long inserted = outputStorage.insert(A, 2, Action.EXECUTE, EmptyActor.INSTANCE); + final long extracted = outputStorage.extract(A, 3, Action.EXECUTE, EmptyActor.INSTANCE); + + // Assert + assertThat(inserted).isEqualTo(2); + assertThat(extracted).isEqualTo(3); + + assertThat(inputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + new ResourceAmount(A, 9) + ); + assertThat(fallbackStorage1.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + new ResourceAmount(A, 10) + ); + assertThat(fallbackStorage2.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + new ResourceAmount(A, 10) + ); + } + + @Test + void shouldModifyPriorityOfOutput( + @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage + ) { + // Arrange + input.setActive(true); + input.setOutputNode(output); + input.setPriority(3); + input.setComponentTypes(Set.of(RelayComponentType.STORAGE)); + inputStorage.addSource(new LimitedStorageImpl(10)); + + final Storage fallbackStorage1 = PriorityStorage.of(new LimitedStorageImpl(5), 1); + outputStorage.addSource(fallbackStorage1); + + final Storage fallbackStorage2 = PriorityStorage.of(new LimitedStorageImpl(5), 3); + outputStorage.addSource(fallbackStorage2); + + // Act + input.setPriority(2); + + // Assert + final long inserted = outputStorage.insert(A, 7, Action.EXECUTE, EmptyActor.INSTANCE); + final long extracted = outputStorage.extract(A, 3, Action.EXECUTE, EmptyActor.INSTANCE); + + assertThat(inserted).isEqualTo(7); + assertThat(extracted).isEqualTo(3); + + assertThat(inputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + new ResourceAmount(A, 2) + ); + assertThat(fallbackStorage1.getAll()).usingRecursiveFieldByFieldElementComparator().isEmpty(); + assertThat(fallbackStorage2.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + new ResourceAmount(A, 2) + ); + } + + @Test + void shouldRespectBlocklistFilter( + @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage + ) { + // Arrange + input.setActive(true); + input.setOutputNode(output); + input.setFilters(Set.of(A, B)); + + inputStorage.addSource(new InMemoryStorageImpl()); + inputStorage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); + inputStorage.insert(B, 9, Action.EXECUTE, EmptyActor.INSTANCE); + inputStorage.insert(C, 8, Action.EXECUTE, EmptyActor.INSTANCE); + + // Act + input.setComponentTypes(Set.of(RelayComponentType.STORAGE)); + + // This update shouldn't arrive. + inputStorage.insert(A, 1, Action.EXECUTE, EmptyActor.INSTANCE); + // This one should. + inputStorage.insert(C, 3, Action.EXECUTE, EmptyActor.INSTANCE); + + final long insertedAllowed = outputStorage.insert(C, 2, Action.EXECUTE, EmptyActor.INSTANCE); + final long insertedNotAllowed = outputStorage.insert(A, 1, Action.EXECUTE, EmptyActor.INSTANCE); + + final long extractedAllowed = outputStorage.extract(C, 1, Action.EXECUTE, EmptyActor.INSTANCE); + final long extractedNotAllowed = outputStorage.extract(A, 1, Action.EXECUTE, EmptyActor.INSTANCE); + + // Assert + assertThat(insertedAllowed).isEqualTo(2); + assertThat(insertedNotAllowed).isZero(); + + assertThat(extractedAllowed).isEqualTo(1); + assertThat(extractedNotAllowed).isZero(); + + assertThat(inputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + new ResourceAmount(A, 11), + new ResourceAmount(B, 9), + new ResourceAmount(C, 12) + ); + assertThat(inputStorage.getStored()).isEqualTo(11 + 9 + 12); + + assertThat(outputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + new ResourceAmount(C, 12) + ); + assertThat(outputStorage.getStored()).isEqualTo(12); + } + + @Test + void shouldRespectAllowlistFilter( + @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage + ) { + // Arrange + input.setActive(true); + input.setOutputNode(output); + input.setFilters(Set.of(A, B)); + input.setFilterMode(FilterMode.ALLOW); + + inputStorage.addSource(new InMemoryStorageImpl()); + inputStorage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); + inputStorage.insert(B, 9, Action.EXECUTE, EmptyActor.INSTANCE); + inputStorage.insert(C, 8, Action.EXECUTE, EmptyActor.INSTANCE); + + // Act + input.setComponentTypes(Set.of(RelayComponentType.STORAGE)); + + // This update should arrive. + inputStorage.insert(A, 1, Action.EXECUTE, EmptyActor.INSTANCE); + // This one shouldn't. + inputStorage.insert(C, 3, Action.EXECUTE, EmptyActor.INSTANCE); + + final long insertedAllowed = outputStorage.insert(A, 2, Action.EXECUTE, EmptyActor.INSTANCE); + final long insertedNotAllowed = outputStorage.insert(C, 1, Action.EXECUTE, EmptyActor.INSTANCE); + + final long extractedAllowed = outputStorage.extract(A, 1, Action.EXECUTE, EmptyActor.INSTANCE); + final long extractedNotAllowed = outputStorage.extract(C, 1, Action.EXECUTE, EmptyActor.INSTANCE); + + // Assert + assertThat(insertedAllowed).isEqualTo(2); + assertThat(insertedNotAllowed).isZero(); + + assertThat(extractedAllowed).isEqualTo(1); + assertThat(extractedNotAllowed).isZero(); + + assertThat(inputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + new ResourceAmount(A, 12), + new ResourceAmount(B, 9), + new ResourceAmount(C, 11) + ); + assertThat(inputStorage.getStored()).isEqualTo(12 + 9 + 11); + + assertThat(outputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + new ResourceAmount(A, 12), + new ResourceAmount(B, 9) + ); + assertThat(outputStorage.getStored()).isEqualTo(12 + 9); + } + + @Test + void shouldRespectFilterNormalizer( + @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage + ) { + // Arrange + input.setActive(true); + input.setOutputNode(output); + input.setFilters(Set.of(A, B)); + input.setFilterMode(FilterMode.ALLOW); + input.setFilterNormalizer(resource -> { + if (resource == A_ALTERNATIVE) { + return A; + } + return resource; + }); + + inputStorage.addSource(new InMemoryStorageImpl()); + inputStorage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); + inputStorage.insert(A_ALTERNATIVE, 3, Action.EXECUTE, EmptyActor.INSTANCE); + inputStorage.insert(B, 9, Action.EXECUTE, EmptyActor.INSTANCE); + inputStorage.insert(C, 8, Action.EXECUTE, EmptyActor.INSTANCE); + + // Act + input.setComponentTypes(Set.of(RelayComponentType.STORAGE)); + + // These updates should arrive. + inputStorage.insert(A, 1, Action.EXECUTE, EmptyActor.INSTANCE); + inputStorage.insert(A_ALTERNATIVE, 2, Action.EXECUTE, EmptyActor.INSTANCE); + // This one shouldn't. + inputStorage.insert(C, 3, Action.EXECUTE, EmptyActor.INSTANCE); + + final long insertedAllowed1 = outputStorage.insert(A, 2, Action.EXECUTE, EmptyActor.INSTANCE); + final long insertedAllowed2 = outputStorage.insert(A_ALTERNATIVE, 3, Action.EXECUTE, EmptyActor.INSTANCE); + final long insertedNotAllowed = outputStorage.insert(C, 1, Action.EXECUTE, EmptyActor.INSTANCE); + + final long extractedAllowed = outputStorage.extract(A, 1, Action.EXECUTE, EmptyActor.INSTANCE); + final long extractedAllowed2 = outputStorage.extract(A_ALTERNATIVE, 2, Action.EXECUTE, EmptyActor.INSTANCE); + final long extractedNotAllowed = outputStorage.extract(C, 1, Action.EXECUTE, EmptyActor.INSTANCE); + + // Assert + assertThat(insertedAllowed1).isEqualTo(2); + assertThat(insertedAllowed2).isEqualTo(3); + assertThat(insertedNotAllowed).isZero(); + + assertThat(extractedAllowed).isEqualTo(1); + assertThat(extractedAllowed2).isEqualTo(2); + assertThat(extractedNotAllowed).isZero(); + + assertThat(inputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + new ResourceAmount(A, 12), + new ResourceAmount(A_ALTERNATIVE, 6), + new ResourceAmount(B, 9), + new ResourceAmount(C, 11) + ); + assertThat(inputStorage.getStored()).isEqualTo(12 + 6 + 9 + 11); + + assertThat(outputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + new ResourceAmount(A, 12), + new ResourceAmount(A_ALTERNATIVE, 6), + new ResourceAmount(B, 9) + ); + assertThat(outputStorage.getStored()).isEqualTo(12 + 6 + 9); + } + + @Test + void shouldUpdateOutputStorageWhenFiltersAreChanged( + @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage + ) { + // Arrange + input.setActive(true); + input.setOutputNode(output); + input.setFilters(Set.of(A)); + input.setFilterMode(FilterMode.BLOCK); + + inputStorage.addSource(new InMemoryStorageImpl()); + inputStorage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); + inputStorage.insert(B, 9, Action.EXECUTE, EmptyActor.INSTANCE); + inputStorage.insert(C, 8, Action.EXECUTE, EmptyActor.INSTANCE); + + // Act + input.setComponentTypes(Set.of(RelayComponentType.STORAGE)); + input.setFilters(Set.of(B)); + + // Assert + assertThat(inputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + new ResourceAmount(A, 10), + new ResourceAmount(B, 9), + new ResourceAmount(C, 8) + ); + assertThat(inputStorage.getStored()).isEqualTo(10 + 9 + 8); + + assertThat(outputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + new ResourceAmount(A, 10), + new ResourceAmount(C, 8) + ); + assertThat(outputStorage.getStored()).isEqualTo(10 + 8); + } + + @Test + void shouldUpdateOutputStorageWhenFilterModeIsChanged( + @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage + ) { + // Arrange + input.setActive(true); + input.setOutputNode(output); + input.setFilters(Set.of(A)); + input.setFilterMode(FilterMode.BLOCK); + + inputStorage.addSource(new InMemoryStorageImpl()); + inputStorage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); + inputStorage.insert(B, 9, Action.EXECUTE, EmptyActor.INSTANCE); + inputStorage.insert(C, 8, Action.EXECUTE, EmptyActor.INSTANCE); + + // Act + input.setComponentTypes(Set.of(RelayComponentType.STORAGE)); + input.setFilterMode(FilterMode.ALLOW); + + // Assert + assertThat(inputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + new ResourceAmount(A, 10), + new ResourceAmount(B, 9), + new ResourceAmount(C, 8) + ); + assertThat(inputStorage.getStored()).isEqualTo(10 + 9 + 8); + + assertThat(outputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + new ResourceAmount(A, 10) + ); + assertThat(outputStorage.getStored()).isEqualTo(10); + } + + @Test + @SetupNetwork(id = "cycle_input", energyStored = 1, energyCapacity = 2) + @SetupNetwork(id = "cycle_input_alt", energyStored = 3, energyCapacity = 4) + void shouldDetectStorageCycles( + @InjectNetwork("cycle_input") final Network inputNetwork, + @InjectNetworkStorageComponent(networkId = "cycle_input") final StorageNetworkComponent inputStorage, + @InjectNetwork("cycle_input_alt") final Network inputAlternativeNetwork, + @InjectNetworkStorageComponent(networkId = "cycle_input_alt") + final StorageNetworkComponent inputAlternativeStorage + ) { + // Act + final RelayOutputNetworkNode cycleOutput = new RelayOutputNetworkNode(0); + cycleOutput.setStorageDelegate(inputAlternativeStorage); + cycleOutput.setNetwork(inputNetwork); + inputNetwork.addContainer(() -> cycleOutput); + + final RelayOutputNetworkNode cycleOutputAlternative = new RelayOutputNetworkNode(0); + cycleOutputAlternative.setStorageDelegate(inputStorage); + cycleOutputAlternative.setNetwork(inputAlternativeNetwork); + inputAlternativeNetwork.addContainer(() -> cycleOutputAlternative); + + inputStorage.addSource(new InMemoryStorageImpl()); + + // Assert + final long inserted1 = inputStorage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); + final long inserted2 = inputAlternativeStorage.insert(A, 2, Action.EXECUTE, EmptyActor.INSTANCE); + + final long extracted1 = inputStorage.extract(A, 1, Action.EXECUTE, EmptyActor.INSTANCE); + final long extracted2 = inputAlternativeStorage.extract(A, 1, Action.EXECUTE, EmptyActor.INSTANCE); + + assertThat(inserted1).isEqualTo(10); + assertThat(inserted2).isZero(); + + assertThat(extracted1).isEqualTo(1); + assertThat(extracted2).isZero(); + + assertThat(inputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + new ResourceAmount(A, 9) + ); + assertThat(inputAlternativeStorage.getAll()).isEmpty(); + + assertThat(inputStorage.getStored()).isEqualTo(9); + assertThat(inputAlternativeStorage.getStored()).isZero(); + } +} diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/storage/StorageNetworkNodeTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/storage/StorageNetworkNodeTest.java index fce1733f2..bb04a9e36 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/storage/StorageNetworkNodeTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/storage/StorageNetworkNodeTest.java @@ -1,20 +1,20 @@ package com.refinedmods.refinedstorage2.api.network.impl.node.storage; import com.refinedmods.refinedstorage2.api.core.Action; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.resource.filter.FilterMode; import com.refinedmods.refinedstorage2.api.storage.AccessMode; import com.refinedmods.refinedstorage2.api.storage.EmptyActor; import com.refinedmods.refinedstorage2.api.storage.Storage; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.api.storage.limited.LimitedStorage; import com.refinedmods.refinedstorage2.api.storage.limited.LimitedStorageImpl; import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedStorageImpl; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; -import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageChannel; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageComponent; import com.refinedmods.refinedstorage2.network.test.NetworkTest; import com.refinedmods.refinedstorage2.network.test.SetupNetwork; -import com.refinedmods.refinedstorage2.network.test.util.FakeActor; +import com.refinedmods.refinedstorage2.network.test.fake.FakeActor; import java.util.Collection; import java.util.Set; @@ -25,9 +25,9 @@ import org.junit.jupiter.params.provider.EnumSource; import org.junit.jupiter.params.provider.ValueSource; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A; -import static com.refinedmods.refinedstorage2.network.test.TestResource.B; -import static com.refinedmods.refinedstorage2.network.test.TestResource.C; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.B; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.C; import static com.refinedmods.refinedstorage2.network.test.nodefactory.AbstractNetworkNodeFactory.PROPERTY_ENERGY_USAGE; import static org.assertj.core.api.Assertions.assertThat; @@ -42,7 +42,7 @@ class StorageNetworkNodeTest { StorageNetworkNode sut; @Test - void testInitialState(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void testInitialState(@InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Act final long inserted = networkStorage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); final long extracted = networkStorage.extract(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); @@ -61,7 +61,7 @@ void testInitialState(@InjectNetworkStorageChannel final StorageChannel networkS } @Test - void shouldInitialize(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void shouldInitialize(@InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange final LimitedStorage limitedStorage = new LimitedStorageImpl(100); limitedStorage.insert(A, 50, Action.EXECUTE, EmptyActor.INSTANCE); @@ -78,7 +78,7 @@ void shouldInitialize(@InjectNetworkStorageChannel final StorageChannel networkS } @Test - void shouldInsert(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void shouldInsert(@InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange final Storage storage = new LimitedStorageImpl(100); activateStorage(storage); @@ -97,7 +97,7 @@ void shouldInsert(@InjectNetworkStorageChannel final StorageChannel networkStora } @Test - void shouldExtract(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void shouldExtract(@InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange final Storage storage = new LimitedStorageImpl(200); storage.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); @@ -120,7 +120,8 @@ void shouldExtract(@InjectNetworkStorageChannel final StorageChannel networkStor } @Test - void shouldRespectAllowlistWhenInserting(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void shouldRespectAllowlistWhenInserting( + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange sut.setFilterMode(FilterMode.ALLOW); sut.setFilters(Set.of(A, B)); @@ -141,7 +142,7 @@ void shouldRespectAllowlistWhenInserting(@InjectNetworkStorageChannel final Stor @Test void shouldRespectEmptyAllowlistWhenInserting( - @InjectNetworkStorageChannel final StorageChannel networkStorage) { + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange sut.setFilterMode(FilterMode.ALLOW); sut.setFilters(Set.of()); @@ -161,7 +162,8 @@ void shouldRespectEmptyAllowlistWhenInserting( } @Test - void shouldRespectBlocklistWhenInserting(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void shouldRespectBlocklistWhenInserting( + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange sut.setFilterMode(FilterMode.BLOCK); sut.setFilters(Set.of(A, B)); @@ -182,7 +184,7 @@ void shouldRespectBlocklistWhenInserting(@InjectNetworkStorageChannel final Stor @Test void shouldRespectEmptyBlocklistWhenInserting( - @InjectNetworkStorageChannel final StorageChannel networkStorage) { + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange sut.setFilterMode(FilterMode.BLOCK); sut.setFilters(Set.of()); @@ -204,7 +206,8 @@ void shouldRespectEmptyBlocklistWhenInserting( @ParameterizedTest @EnumSource(AccessMode.class) void shouldRespectAccessModeWhenInserting(final AccessMode accessMode, - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent + final StorageNetworkComponent networkStorage ) { // Arrange sut.setAccessMode(accessMode); @@ -225,7 +228,8 @@ void shouldRespectAccessModeWhenInserting(final AccessMode accessMode, @ParameterizedTest @EnumSource(AccessMode.class) void shouldRespectAccessModeWhenExtracting(final AccessMode accessMode, - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent + final StorageNetworkComponent networkStorage ) { // Arrange sut.setAccessMode(accessMode); @@ -245,7 +249,7 @@ void shouldRespectAccessModeWhenExtracting(final AccessMode accessMode, } @Test - void shouldNotInsertWhenInactive(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void shouldNotInsertWhenInactive(@InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange final Storage storage = new LimitedStorageImpl(100); activateStorage(storage); @@ -259,7 +263,7 @@ void shouldNotInsertWhenInactive(@InjectNetworkStorageChannel final StorageChann } @Test - void shouldNotExtractWhenInactive(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void shouldNotExtractWhenInactive(@InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange final Storage storage = new LimitedStorageImpl(100); activateStorage(storage); @@ -275,7 +279,7 @@ void shouldNotExtractWhenInactive(@InjectNetworkStorageChannel final StorageChan @Test void shouldHideStorageContentsWhenInactive( - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange final Storage storage = new LimitedStorageImpl(100); @@ -291,7 +295,8 @@ void shouldHideStorageContentsWhenInactive( } @Test - void shouldShowStorageContentsWhenActive(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void shouldShowStorageContentsWhenActive( + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange final Storage storage = new LimitedStorageImpl(100); storage.insert(A, 50, Action.EXECUTE, EmptyActor.INSTANCE); @@ -308,7 +313,7 @@ void shouldShowStorageContentsWhenActive(@InjectNetworkStorageChannel final Stor } @Test - void shouldNotInsertWhenFull(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void shouldNotInsertWhenFull(@InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange final Storage storage = new LimitedStorageImpl(100); storage.insert(A, 95, Action.EXECUTE, EmptyActor.INSTANCE); @@ -334,7 +339,7 @@ void shouldNotInsertWhenFull(@InjectNetworkStorageChannel final StorageChannel n @Test void shouldNotInsertWhenFullWhenStorageVoidsExcessButIsNotInAllowlistMode( - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange final LimitedStorageImpl storage = new LimitedStorageImpl(100); @@ -355,7 +360,7 @@ void shouldNotInsertWhenFullWhenStorageVoidsExcessButIsNotInAllowlistMode( @Test void shouldNotInsertWhenStorageVoidsExcessAndInAllowlistModeWithoutConfiguredFilter( - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange final LimitedStorageImpl storage = new LimitedStorageImpl(100); @@ -374,7 +379,7 @@ void shouldNotInsertWhenStorageVoidsExcessAndInAllowlistModeWithoutConfiguredFil @Test void shouldInsertWhenFullWhenStorageVoidsExcessAndIsInAllowlistMode( - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange final LimitedStorageImpl storage = new LimitedStorageImpl(100); @@ -400,7 +405,7 @@ void shouldInsertWhenFullWhenStorageVoidsExcessAndIsInAllowlistMode( } @Test - void shouldTrackChanges(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void shouldTrackChanges(@InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange activateStorage(new TrackedStorageImpl(new LimitedStorageImpl(100), () -> 0L)); @@ -426,7 +431,7 @@ class PriorityTest { @ValueSource(booleans = {true, false}) void shouldRespectPriority( final boolean oneHasPriority, - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange final LimitedStorageImpl storage1 = new LimitedStorageImpl(100); diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/security/SecurityNetworkComponentImplTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/security/SecurityNetworkComponentImplTest.java index c9a565eb4..50494ba03 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/security/SecurityNetworkComponentImplTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/security/SecurityNetworkComponentImplTest.java @@ -3,8 +3,8 @@ import com.refinedmods.refinedstorage2.api.network.impl.node.security.SecurityDecisionProviderProxyNetworkNode; import com.refinedmods.refinedstorage2.api.network.security.SecurityNetworkComponent; import com.refinedmods.refinedstorage2.api.network.security.SecurityPolicy; -import com.refinedmods.refinedstorage2.network.test.util.FakePermissions; -import com.refinedmods.refinedstorage2.network.test.util.FakeSecurityActors; +import com.refinedmods.refinedstorage2.network.test.fake.FakePermissions; +import com.refinedmods.refinedstorage2.network.test.fake.FakeSecurityActors; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/storage/StorageNetworkComponentImplTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/storage/StorageNetworkComponentImplTest.java index 3b706ed4c..1c234496b 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/storage/StorageNetworkComponentImplTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/storage/StorageNetworkComponentImplTest.java @@ -34,8 +34,8 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A; -import static com.refinedmods.refinedstorage2.network.test.TestResource.B; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.B; import static org.assertj.core.api.Assertions.assertThat; class StorageNetworkComponentImplTest { diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/AbstractModInitializer.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/AbstractModInitializer.java index 8bfa28fdd..82f97c96d 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/AbstractModInitializer.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/AbstractModInitializer.java @@ -4,7 +4,9 @@ import com.refinedmods.refinedstorage2.api.network.impl.energy.EnergyNetworkComponentImpl; import com.refinedmods.refinedstorage2.api.network.impl.node.GraphNetworkComponentImpl; import com.refinedmods.refinedstorage2.api.network.impl.node.SimpleNetworkNode; +import com.refinedmods.refinedstorage2.api.network.impl.security.SecurityNetworkComponentImpl; import com.refinedmods.refinedstorage2.api.network.node.GraphNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.security.SecurityNetworkComponent; import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.api.PlatformApiProxy; @@ -267,6 +269,10 @@ private void registerNetworkComponents() { PlatformSecurityNetworkComponent.class, network -> new PlatformSecurityNetworkComponentImpl(PlatformApi.INSTANCE.createDefaultSecurityPolicy()) ); + PlatformApi.INSTANCE.getNetworkComponentMapFactory().addFactory( + SecurityNetworkComponent.class, + network -> new SecurityNetworkComponentImpl(PlatformApi.INSTANCE.createDefaultSecurityPolicy()) + ); } private void registerWirelessTransmitterRangeModifiers() { diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayBlockEntity.java index 3dfaa0320..ffd4ed6e8 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayBlockEntity.java @@ -1,17 +1,25 @@ package com.refinedmods.refinedstorage2.platform.common.networking; +import com.refinedmods.refinedstorage2.api.network.impl.node.relay.RelayComponentType; +import com.refinedmods.refinedstorage2.api.network.impl.node.relay.RelayInputNetworkNode; +import com.refinedmods.refinedstorage2.api.network.impl.node.relay.RelayOutputNetworkNode; +import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.api.resource.filter.FilterMode; import com.refinedmods.refinedstorage2.api.storage.AccessMode; import com.refinedmods.refinedstorage2.platform.api.support.network.InWorldNetworkNodeContainer; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceContainer; +import com.refinedmods.refinedstorage2.platform.common.Platform; import com.refinedmods.refinedstorage2.platform.common.content.BlockEntities; import com.refinedmods.refinedstorage2.platform.common.content.ContentNames; import com.refinedmods.refinedstorage2.platform.common.storage.AccessModeSettings; import com.refinedmods.refinedstorage2.platform.common.support.FilterModeSettings; +import com.refinedmods.refinedstorage2.platform.common.support.FilterWithFuzzyMode; +import com.refinedmods.refinedstorage2.platform.common.support.RedstoneMode; import com.refinedmods.refinedstorage2.platform.common.support.containermenu.NetworkNodeMenuProvider; import com.refinedmods.refinedstorage2.platform.common.support.network.AbstractRedstoneModeNetworkNodeContainerBlockEntity; import com.refinedmods.refinedstorage2.platform.common.support.resource.ResourceContainerImpl; +import java.util.HashSet; +import java.util.Set; import javax.annotation.Nullable; import net.minecraft.core.BlockPos; @@ -27,37 +35,53 @@ import static java.util.Objects.requireNonNull; -// TODO: Move to network pkg. -// TODO: Network Pkg - Relay output energy usage correction -// TODO: Network Pkg - Storage. -public class RelayBlockEntity extends AbstractRedstoneModeNetworkNodeContainerBlockEntity +public class RelayBlockEntity extends AbstractRedstoneModeNetworkNodeContainerBlockEntity implements NetworkNodeMenuProvider { private static final String TAG_PASS_THROUGH = "passthrough"; private static final String TAG_PASS_ENERGY = "passenergy"; - private static final String TAG_PASS_STORAGE = "passstorage"; private static final String TAG_PASS_SECURITY = "passsecurity"; + private static final String TAG_PASS_STORAGE = "passstorage"; private static final String TAG_FILTER_MODE = "fim"; - private static final String TAG_FILTERS = "filters"; private static final String TAG_ACCESS_MODE = "am"; private static final String TAG_PRIORITY = "pri"; - private final ResourceContainer filters = ResourceContainerImpl.createForFilter(); - private final RelayOuterNetworkNode outerNode; + private final FilterWithFuzzyMode filter; + private final RelayOutputNetworkNode outputNode; + private boolean passThrough = true; private FilterMode filterMode = FilterMode.BLOCK; private AccessMode accessMode = AccessMode.INSERT_EXTRACT; private int priority = 0; public RelayBlockEntity(final BlockPos pos, final BlockState state) { - super(BlockEntities.INSTANCE.getRelay(), pos, state, new RelayMainNetworkNode()); - this.outerNode = new RelayOuterNetworkNode(); - this.mainNode.setOuterNode(outerNode); - this.addContainer(new RelayOuterNetworkNodeContainer(this, outerNode, "outer")); - this.filters.setListener(this::filterContainerChanged); + super(BlockEntities.INSTANCE.getRelay(), pos, state, new RelayInputNetworkNode( + Platform.INSTANCE.getConfig().getRelay().getInputNetworkEnergyUsage() + )); + this.outputNode = new RelayOutputNetworkNode( + Platform.INSTANCE.getConfig().getRelay().getOutputNetworkEnergyUsage() + ); + this.mainNode.setOutputNode(outputNode); + this.filter = FilterWithFuzzyMode.createAndListenForUniqueFilters( + ResourceContainerImpl.createForFilter(), + this::setChanged, + this::filterContainerChanged + ); + this.mainNode.setFilterNormalizer(filter.createNormalizer()); + this.addContainer(new RelayOutputNetworkNodeContainer(this, outputNode)); + setRedstoneMode(RedstoneMode.LOW); + } + + boolean isFuzzyMode() { + return filter.isFuzzyMode(); + } + + void setFuzzyMode(final boolean fuzzyMode) { + filter.setFuzzyMode(fuzzyMode); + setChanged(); } - private void filterContainerChanged() { - outerNode.setFilter(filterMode, filters.getUniqueResources()); + private void filterContainerChanged(final Set filters) { + mainNode.setFilters(filters); setChanged(); } @@ -67,7 +91,7 @@ int getPriority() { void setPriority(final int priority) { this.priority = priority; - this.outerNode.setPriority(priority); + this.mainNode.setPriority(priority); setChanged(); } @@ -77,7 +101,7 @@ AccessMode getAccessMode() { void setAccessMode(final AccessMode accessMode) { this.accessMode = accessMode; - this.outerNode.setAccessMode(accessMode); + mainNode.setAccessMode(accessMode); setChanged(); } @@ -87,46 +111,44 @@ FilterMode getFilterMode() { void setFilterMode(final FilterMode filterMode) { this.filterMode = filterMode; - this.outerNode.setFilter(filterMode, filters.getUniqueResources()); + mainNode.setFilterMode(filterMode); setChanged(); } boolean isPassEnergy() { - return mainNode.isPassEnergy(); + return mainNode.hasComponentType(RelayComponentType.ENERGY); } void setPassEnergy(final boolean passEnergy) { - mainNode.setPassEnergy(passEnergy); + mainNode.updateComponentType(RelayComponentType.ENERGY, passEnergy); setChanged(); } boolean isPassStorage() { - return mainNode.isPassStorage(); + return mainNode.hasComponentType(RelayComponentType.STORAGE); } void setPassStorage(final boolean passStorage) { - mainNode.setPassStorage(passStorage); + mainNode.updateComponentType(RelayComponentType.STORAGE, passStorage); setChanged(); } boolean isPassSecurity() { - return mainNode.isPassSecurity(); + return mainNode.hasComponentType(RelayComponentType.SECURITY); } void setPassSecurity(final boolean passSecurity) { - mainNode.setPassSecurity(passSecurity); + mainNode.updateComponentType(RelayComponentType.SECURITY, passSecurity); setChanged(); } boolean isPassThrough() { - return mainNode.isPassThrough(); + return passThrough; } void setPassThrough(final boolean passThrough) { - mainNode.setPassThrough(passThrough); - mainNode.setPassEnergy(false); - mainNode.setPassSecurity(false); - mainNode.setPassStorage(false); + this.passThrough = passThrough; + this.mainNode.setComponentTypes(Set.of()); setChanged(); updateContainers(); } @@ -142,18 +164,18 @@ Direction getDirectionInternal() { @Override protected void activenessChanged(final boolean newActive) { super.activenessChanged(newActive); - outerNode.setActive(newActive); + outputNode.setActive(newActive); updateContainers(); } @Override - protected InWorldNetworkNodeContainer createMainContainer(final RelayMainNetworkNode node) { - return new RelayMainNetworkNodeContainer(this, node, MAIN_CONTAINER_NAME); + protected InWorldNetworkNodeContainer createMainContainer(final RelayInputNetworkNode node) { + return new RelayInputNetworkNodeContainer(this, node); } @Override public void writeScreenOpeningData(final ServerPlayer player, final FriendlyByteBuf buf) { - filters.writeToUpdatePacket(buf); + filter.getFilterContainer().writeToUpdatePacket(buf); } @Override @@ -164,18 +186,18 @@ public Component getDisplayName() { @Nullable @Override public AbstractContainerMenu createMenu(final int syncId, final Inventory inventory, final Player player) { - return new RelayContainerMenu(syncId, player, this, filters); + return new RelayContainerMenu(syncId, player, this, filter.getFilterContainer()); } @Override public void writeConfiguration(final CompoundTag tag) { super.writeConfiguration(tag); - tag.put(TAG_FILTERS, filters.toTag()); + filter.save(tag); tag.putInt(TAG_FILTER_MODE, FilterModeSettings.getFilterMode(filterMode)); - tag.putBoolean(TAG_PASS_THROUGH, mainNode.isPassThrough()); - tag.putBoolean(TAG_PASS_ENERGY, mainNode.isPassEnergy()); - tag.putBoolean(TAG_PASS_STORAGE, mainNode.isPassStorage()); - tag.putBoolean(TAG_PASS_SECURITY, mainNode.isPassSecurity()); + tag.putBoolean(TAG_PASS_THROUGH, passThrough); + tag.putBoolean(TAG_PASS_ENERGY, mainNode.hasComponentType(RelayComponentType.ENERGY)); + tag.putBoolean(TAG_PASS_STORAGE, mainNode.hasComponentType(RelayComponentType.STORAGE)); + tag.putBoolean(TAG_PASS_SECURITY, mainNode.hasComponentType(RelayComponentType.SECURITY)); tag.putInt(TAG_ACCESS_MODE, AccessModeSettings.getAccessMode(accessMode)); tag.putInt(TAG_PRIORITY, priority); } @@ -183,32 +205,36 @@ public void writeConfiguration(final CompoundTag tag) { @Override public void readConfiguration(final CompoundTag tag) { super.readConfiguration(tag); - if (tag.contains(TAG_FILTERS)) { - filters.fromTag(tag.getCompound(TAG_FILTERS)); - } + filter.load(tag); if (tag.contains(TAG_FILTER_MODE)) { filterMode = FilterModeSettings.getFilterMode(tag.getInt(TAG_FILTER_MODE)); } - outerNode.setFilter(filterMode, filters.getUniqueResources()); + mainNode.setFilterMode(filterMode); if (tag.contains(TAG_PASS_THROUGH)) { - mainNode.setPassThrough(tag.getBoolean(TAG_PASS_THROUGH)); - } - if (tag.contains(TAG_PASS_ENERGY)) { - mainNode.setPassEnergy(tag.getBoolean(TAG_PASS_ENERGY)); - } - if (tag.contains(TAG_PASS_STORAGE)) { - mainNode.setPassStorage(tag.getBoolean(TAG_PASS_STORAGE)); - } - if (tag.contains(TAG_PASS_SECURITY)) { - mainNode.setPassSecurity(tag.getBoolean(TAG_PASS_SECURITY)); + passThrough = tag.getBoolean(TAG_PASS_THROUGH); } + mainNode.setComponentTypes(getComponentTypes(tag)); if (tag.contains(TAG_ACCESS_MODE)) { accessMode = AccessModeSettings.getAccessMode(tag.getInt(TAG_ACCESS_MODE)); } - outerNode.setAccessMode(accessMode); + mainNode.setAccessMode(accessMode); if (tag.contains(TAG_PRIORITY)) { priority = tag.getInt(TAG_PRIORITY); } - outerNode.setPriority(priority); + mainNode.setPriority(priority); + } + + private Set getComponentTypes(final CompoundTag tag) { + final Set types = new HashSet<>(); + if (tag.getBoolean(TAG_PASS_ENERGY)) { + types.add(RelayComponentType.ENERGY); + } + if (tag.getBoolean(TAG_PASS_SECURITY)) { + types.add(RelayComponentType.SECURITY); + } + if (tag.getBoolean(TAG_PASS_STORAGE)) { + types.add(RelayComponentType.STORAGE); + } + return types; } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayContainerMenu.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayContainerMenu.java index 9d0a81652..86a6494e7 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayContainerMenu.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayContainerMenu.java @@ -84,6 +84,7 @@ protected void onChangedOnClient(final Boolean newValue) { registerProperty(new ClientProperty<>(PropertyTypes.FILTER_MODE, FilterMode.BLOCK)); registerProperty(new ClientProperty<>(StoragePropertyTypes.ACCESS_MODE, AccessMode.INSERT_EXTRACT)); registerProperty(new ClientProperty<>(StoragePropertyTypes.PRIORITY, 0)); + registerProperty(new ClientProperty<>(PropertyTypes.FUZZY_MODE, false)); } @Override @@ -128,6 +129,11 @@ protected void registerServerProperties(final RelayBlockEntity blockEntity) { blockEntity::getPriority, blockEntity::setPriority )); + registerProperty(new ServerProperty<>( + PropertyTypes.FUZZY_MODE, + blockEntity::isFuzzyMode, + blockEntity::setFuzzyMode + )); } boolean isPassThrough() { diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayMainNetworkNodeContainer.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayInputNetworkNodeContainer.java similarity index 80% rename from refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayMainNetworkNodeContainer.java rename to refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayInputNetworkNodeContainer.java index 099b0fad7..f20428859 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayMainNetworkNodeContainer.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayInputNetworkNodeContainer.java @@ -7,13 +7,11 @@ import net.minecraft.core.Direction; import net.minecraft.world.level.block.state.BlockState; -class RelayMainNetworkNodeContainer extends InWorldNetworkNodeContainerImpl { +class RelayInputNetworkNodeContainer extends InWorldNetworkNodeContainerImpl { private final RelayBlockEntity blockEntity; - RelayMainNetworkNodeContainer(final RelayBlockEntity blockEntity, - final NetworkNode node, - final String name) { - super(blockEntity, node, name, 0, blockEntity, null); + RelayInputNetworkNodeContainer(final RelayBlockEntity blockEntity, final NetworkNode node) { + super(blockEntity, node, "input", 0, blockEntity, null); this.blockEntity = blockEntity; } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayMainNetworkNode.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayMainNetworkNode.java deleted file mode 100644 index ba65b471b..000000000 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayMainNetworkNode.java +++ /dev/null @@ -1,108 +0,0 @@ -package com.refinedmods.refinedstorage2.platform.common.networking; - -import com.refinedmods.refinedstorage2.api.network.Network; -import com.refinedmods.refinedstorage2.api.network.energy.EnergyNetworkComponent; -import com.refinedmods.refinedstorage2.api.network.impl.node.AbstractNetworkNode; -import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; -import com.refinedmods.refinedstorage2.platform.api.security.PlatformSecurityNetworkComponent; -import com.refinedmods.refinedstorage2.platform.common.Platform; - -import javax.annotation.Nullable; - -public class RelayMainNetworkNode extends AbstractNetworkNode { - private final long energyUsage; - - private boolean passThrough = true; - private boolean passEnergy = false; - private boolean passStorage = false; - private boolean passSecurity = false; - @Nullable - private RelayOuterNetworkNode outerNode; - - RelayMainNetworkNode() { - this.energyUsage = Platform.INSTANCE.getConfig().getRelay().getInputNetworkEnergyUsage(); - } - - void setOuterNode(@Nullable final RelayOuterNetworkNode outerNode) { - this.outerNode = outerNode; - } - - @Override - public void setNetwork(@Nullable final Network network) { - super.setNetwork(network); - notifyOuterNodeAboutComponents(); - } - - @Override - protected void onActiveChanged(final boolean newActive) { - super.onActiveChanged(newActive); - notifyOuterNodeAboutComponents(); - } - - private void notifyOuterNodeAboutComponents() { - if (outerNode == null) { - return; - } - if (network == null || passThrough || !isActive()) { - outerNode.setMainSecurityComponent(null); - outerNode.setMainEnergyComponent(null); - outerNode.clearMainStorage(); - return; - } - outerNode.setMainEnergyComponent( - passEnergy ? network.getComponent(EnergyNetworkComponent.class) : null - ); - outerNode.setMainSecurityComponent( - passSecurity ? network.getComponent(PlatformSecurityNetworkComponent.class) : null - ); - final StorageNetworkComponent storage = passStorage - ? network.getComponent(StorageNetworkComponent.class) - : null; - if (storage == null) { - outerNode.clearMainStorage(); - } else { - outerNode.setMainStorage(storage); - } - } - - boolean isPassThrough() { - return passThrough; - } - - void setPassThrough(final boolean passThrough) { - this.passThrough = passThrough; - notifyOuterNodeAboutComponents(); - } - - boolean isPassEnergy() { - return passEnergy; - } - - void setPassEnergy(final boolean passEnergy) { - this.passEnergy = passEnergy; - notifyOuterNodeAboutComponents(); - } - - boolean isPassStorage() { - return passStorage; - } - - void setPassStorage(final boolean passStorage) { - this.passStorage = passStorage; - notifyOuterNodeAboutComponents(); - } - - boolean isPassSecurity() { - return passSecurity; - } - - void setPassSecurity(final boolean passSecurity) { - this.passSecurity = passSecurity; - notifyOuterNodeAboutComponents(); - } - - @Override - public long getEnergyUsage() { - return energyUsage; - } -} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayOuterNetworkNode.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayOuterNetworkNode.java deleted file mode 100644 index ec5e3c83d..000000000 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayOuterNetworkNode.java +++ /dev/null @@ -1,136 +0,0 @@ -package com.refinedmods.refinedstorage2.platform.common.networking; - -import com.refinedmods.refinedstorage2.api.network.energy.EnergyNetworkComponent; -import com.refinedmods.refinedstorage2.api.network.energy.EnergyProvider; -import com.refinedmods.refinedstorage2.api.network.impl.node.AbstractNetworkNode; -import com.refinedmods.refinedstorage2.api.network.security.Permission; -import com.refinedmods.refinedstorage2.api.network.security.SecurityActor; -import com.refinedmods.refinedstorage2.api.network.security.SecurityDecision; -import com.refinedmods.refinedstorage2.api.network.security.SecurityDecisionProvider; -import com.refinedmods.refinedstorage2.api.network.security.SecurityNetworkComponent; -import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; -import com.refinedmods.refinedstorage2.api.network.storage.StorageProvider; -import com.refinedmods.refinedstorage2.api.resource.ResourceKey; -import com.refinedmods.refinedstorage2.api.resource.filter.FilterMode; -import com.refinedmods.refinedstorage2.api.storage.AccessMode; -import com.refinedmods.refinedstorage2.api.storage.Storage; -import com.refinedmods.refinedstorage2.platform.api.security.PlatformSecurityNetworkComponent; -import com.refinedmods.refinedstorage2.platform.common.Platform; - -import java.util.Set; -import javax.annotation.Nullable; - -class RelayOuterNetworkNode extends AbstractNetworkNode - implements EnergyProvider, SecurityDecisionProvider, StorageProvider { - private final RelayOuterNetworkNodeStorage outerStorage = new RelayOuterNetworkNodeStorage(); - private final long energyUsage; - - @Nullable - private EnergyNetworkComponent mainEnergyComponent; - @Nullable - private PlatformSecurityNetworkComponent mainSecurityComponent; - - RelayOuterNetworkNode() { - this.energyUsage = Platform.INSTANCE.getConfig().getRelay().getOutputNetworkEnergyUsage(); - } - - void setMainEnergyComponent(@Nullable final EnergyNetworkComponent mainEnergyComponent) { - this.mainEnergyComponent = mainEnergyComponent; - } - - void setMainSecurityComponent(@Nullable final PlatformSecurityNetworkComponent mainSecurityComponent) { - this.mainSecurityComponent = mainSecurityComponent; - } - - @Override - public boolean contains(final EnergyProvider energyProvider) { - return energyProvider == mainEnergyComponent - || (mainEnergyComponent != null && mainEnergyComponent.contains(energyProvider)); - } - - @Override - public boolean contains(final SecurityNetworkComponent component) { - return component == mainSecurityComponent - || (mainSecurityComponent != null && mainSecurityComponent.contains(component)); - } - - @Override - public long getStored() { - if (mainEnergyComponent == null || mainEnergyComponent.contains(mainEnergyComponent)) { - return 0; - } - return mainEnergyComponent.getStored(); - } - - @Override - public long getCapacity() { - if (mainEnergyComponent == null || mainEnergyComponent.contains(mainEnergyComponent)) { - return 0; - } - return mainEnergyComponent.getCapacity(); - } - - @Override - public long extract(final long amount) { - if (mainEnergyComponent == null || mainEnergyComponent.contains(mainEnergyComponent)) { - return 0; - } - return mainEnergyComponent.extract(amount); - } - - @Override - public long getEnergyUsage() { - if (mainEnergyComponent != null || mainSecurityComponent != null || outerStorage.isActive()) { - return energyUsage; - } - return 0; - } - - @Override - public SecurityDecision isAllowed(final Permission permission, final SecurityActor actor) { - if (mainSecurityComponent == null || mainSecurityComponent.contains(mainSecurityComponent)) { - return SecurityDecision.PASS; - } - return mainSecurityComponent.isAllowed(permission, actor) - ? SecurityDecision.ALLOW - : SecurityDecision.DENY; - } - - @Override - public boolean isProviderActive() { - return isActive() && mainSecurityComponent != null; - } - - @Override - public Storage getStorage() { - return outerStorage; - } - - void clearMainStorage() { - outerStorage.setMainStorageChannel(null); - } - - void setMainStorage(final StorageNetworkComponent storage) { - outerStorage.setMainStorageChannel(storage); - } - - void setFilter(final FilterMode filterMode, final Set filters) { - outerStorage.resetMainStorageChannel(() -> { - outerStorage.setFilterMode(filterMode); - outerStorage.setFilters(filters); - }); - } - - void setAccessMode(final AccessMode accessMode) { - outerStorage.setAccessMode(accessMode); - } - - public void setPriority(final int priority) { - outerStorage.setPriority(priority); - if (network == null) { - return; - } - final StorageNetworkComponent storage = network.getComponent(StorageNetworkComponent.class); - storage.sortSources(); - } -} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayOuterNetworkNodeContainer.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayOutputNetworkNodeContainer.java similarity index 58% rename from refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayOuterNetworkNodeContainer.java rename to refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayOutputNetworkNodeContainer.java index 5a0c65501..0d45d4d91 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayOuterNetworkNodeContainer.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayOutputNetworkNodeContainer.java @@ -1,26 +1,25 @@ package com.refinedmods.refinedstorage2.platform.common.networking; +import com.refinedmods.refinedstorage2.api.network.impl.node.relay.RelayOutputNetworkNode; import com.refinedmods.refinedstorage2.platform.api.support.network.ConnectionSink; import com.refinedmods.refinedstorage2.platform.common.support.network.InWorldNetworkNodeContainerImpl; import net.minecraft.core.Direction; import net.minecraft.world.level.block.state.BlockState; -class RelayOuterNetworkNodeContainer extends InWorldNetworkNodeContainerImpl { +class RelayOutputNetworkNodeContainer extends InWorldNetworkNodeContainerImpl { private final RelayBlockEntity blockEntity; - RelayOuterNetworkNodeContainer(final RelayBlockEntity blockEntity, - final RelayOuterNetworkNode node, - final String name) { - super(blockEntity, node, name, 0, blockEntity, null); + RelayOutputNetworkNodeContainer(final RelayBlockEntity blockEntity, final RelayOutputNetworkNode node) { + super(blockEntity, node, "output", 0, blockEntity, null); this.blockEntity = blockEntity; } - // The outer network node container must always have an outgoing and incoming connection. - // If not, network node containers after the outer network node container may end up without a network + // The output network node container must always have an outgoing and incoming connection. + // If not, network node containers after the output network node container may end up without a network // because the graph algorithm won't be able to work properly and won't be able to reassign a new network. - // The outer network node container *never* provides a connection with the main network node container. - // The main network node container controls whether the outer network node container is connected. + // The output network node container *never* provides a connection with the input network node container. + // The input network node container controls whether the output network node container is connected. @Override public void addOutgoingConnections(final ConnectionSink sink) { final Direction direction = blockEntity.getDirectionInternal(); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayScreen.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayScreen.java index 16b20abf1..0192726f9 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayScreen.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayScreen.java @@ -7,6 +7,7 @@ import com.refinedmods.refinedstorage2.platform.common.support.AbstractFilterScreen; import com.refinedmods.refinedstorage2.platform.common.support.containermenu.PropertyTypes; import com.refinedmods.refinedstorage2.platform.common.support.widget.AbstractSideButtonWidget; +import com.refinedmods.refinedstorage2.platform.common.support.widget.FuzzyModeSideButtonWidget; import javax.annotation.Nullable; @@ -38,6 +39,8 @@ public class RelayScreen extends AbstractFilterScreen @Nullable private AbstractSideButtonWidget filterModeButton; @Nullable + private AbstractSideButtonWidget fuzzyModeButton; + @Nullable private AbstractSideButtonWidget accessModeButton; @Nullable private AbstractSideButtonWidget priorityButton; @@ -89,6 +92,13 @@ private void addStorageButtons(final boolean visible) { filterModeButton.visible = visible; addSideButton(filterModeButton); + fuzzyModeButton = new FuzzyModeSideButtonWidget( + getMenu().getProperty(PropertyTypes.FUZZY_MODE), + FuzzyModeSideButtonWidget.Type.STORAGE + ); + fuzzyModeButton.visible = visible; + addSideButton(fuzzyModeButton); + accessModeButton = new AccessModeSideButtonWidget(getMenu().getProperty(StoragePropertyTypes.ACCESS_MODE)); accessModeButton.visible = visible; addSideButton(accessModeButton); @@ -104,6 +114,11 @@ private void addStorageButtons(final boolean visible) { @Override public void passThroughChanged(final boolean passThrough, final boolean passStorage) { + updatePassButtons(passThrough); + updateStorageButtons(passThrough, passStorage); + } + + private void updatePassButtons(final boolean passThrough) { if (passEnergyButton != null) { passEnergyButton.visible = !passThrough; } @@ -113,9 +128,15 @@ public void passThroughChanged(final boolean passThrough, final boolean passStor if (passStorageButton != null) { passStorageButton.visible = !passThrough; } + } + + private void updateStorageButtons(final boolean passThrough, final boolean passStorage) { if (filterModeButton != null) { filterModeButton.visible = !passThrough && passStorage; } + if (fuzzyModeButton != null) { + fuzzyModeButton.visible = !passThrough && passStorage; + } if (accessModeButton != null) { accessModeButton.visible = !passThrough && passStorage; } diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/lang/en_us.json b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/lang/en_us.json index 0f4d6e74f..6e06c5772 100644 --- a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/lang/en_us.json +++ b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/lang/en_us.json @@ -153,7 +153,7 @@ "gui.refinedstorage2.security_manager.no_fallback_security_card_consequence": "Add a Fallback Security Card to this slot to set permissions for every player without a Security Card. By default, all actions are denied.", "gui.refinedstorage2.relay.filter_help": "Resources which should be exposed from the input network to the output network if the Relay isn't in pass-through mode.", "gui.refinedstorage2.relay.pass_through": "Pass-through", - "gui.refinedstorage2.relay.pass_through.help": "Whether this device should pass-through the entire input network signal.", + "gui.refinedstorage2.relay.pass_through.help": "Whether this device should pass-through the entire input network signal as-is. Turn this off to selectively expose components to the output network.", "gui.refinedstorage2.relay.pass_energy": "Pass energy", "gui.refinedstorage2.relay.pass_energy.help": "Whether this device should pass the energy buffer from the input network to the output network.", "gui.refinedstorage2.relay.pass_storage": "Pass storage", diff --git a/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/channel/StorageChannel.java b/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/channel/StorageChannel.java index 29299d15c..55cf8eb60 100644 --- a/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/channel/StorageChannel.java +++ b/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/channel/StorageChannel.java @@ -44,7 +44,7 @@ public interface StorageChannel extends Storage, TrackedStorage { void sortSources(); /** - * Adds a source to the channel. + * Adds a source to the channel and resorts all the sources. * * @param source the source */ diff --git a/refinedstorage2-storage-api/src/test/java/com/refinedmods/refinedstorage2/api/storage/composite/PrioritizedStorage.java b/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/composite/PriorityStorage.java similarity index 53% rename from refinedstorage2-storage-api/src/test/java/com/refinedmods/refinedstorage2/api/storage/composite/PrioritizedStorage.java rename to refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/composite/PriorityStorage.java index fafebcb41..034996742 100644 --- a/refinedstorage2-storage-api/src/test/java/com/refinedmods/refinedstorage2/api/storage/composite/PrioritizedStorage.java +++ b/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/composite/PriorityStorage.java @@ -3,14 +3,21 @@ import com.refinedmods.refinedstorage2.api.storage.AbstractProxyStorage; import com.refinedmods.refinedstorage2.api.storage.Storage; -public class PrioritizedStorage extends AbstractProxyStorage implements Priority { +import org.apiguardian.api.API; + +@API(status = API.Status.STABLE, since = "2.0.0-milestone.3.6") +public class PriorityStorage extends AbstractProxyStorage implements Priority { private int priority; - public PrioritizedStorage(final int priority, final Storage delegate) { + private PriorityStorage(final int priority, final Storage delegate) { super(delegate); this.priority = priority; } + public static PriorityStorage of(final Storage delegate, final int priority) { + return new PriorityStorage(priority, delegate); + } + public void setPriority(final int priority) { this.priority = priority; } @@ -20,3 +27,4 @@ public int getPriority() { return priority; } } + diff --git a/refinedstorage2-storage-api/src/test/java/com/refinedmods/refinedstorage2/api/storage/channel/StorageChannelImplTest.java b/refinedstorage2-storage-api/src/test/java/com/refinedmods/refinedstorage2/api/storage/channel/StorageChannelImplTest.java index 834f0c639..cf3f1c9cd 100644 --- a/refinedstorage2-storage-api/src/test/java/com/refinedmods/refinedstorage2/api/storage/channel/StorageChannelImplTest.java +++ b/refinedstorage2-storage-api/src/test/java/com/refinedmods/refinedstorage2/api/storage/channel/StorageChannelImplTest.java @@ -6,7 +6,7 @@ import com.refinedmods.refinedstorage2.api.resource.list.listenable.ResourceListListener; import com.refinedmods.refinedstorage2.api.storage.EmptyActor; import com.refinedmods.refinedstorage2.api.storage.Storage; -import com.refinedmods.refinedstorage2.api.storage.composite.PrioritizedStorage; +import com.refinedmods.refinedstorage2.api.storage.composite.PriorityStorage; import com.refinedmods.refinedstorage2.api.storage.limited.LimitedStorageImpl; import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedResource; import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedStorageImpl; @@ -266,9 +266,9 @@ void shouldNotBeAbleToRetrieveNonExistentResource() { @Test void shouldSortSources() { // Arrange - final PrioritizedStorage storage1 = new PrioritizedStorage(0, new LimitedStorageImpl(10)); - final PrioritizedStorage storage2 = new PrioritizedStorage(0, new LimitedStorageImpl(10)); - final PrioritizedStorage storage3 = new PrioritizedStorage(0, new LimitedStorageImpl(10)); + final PriorityStorage storage1 = PriorityStorage.of(new LimitedStorageImpl(10), 0); + final PriorityStorage storage2 = PriorityStorage.of(new LimitedStorageImpl(10), 0); + final PriorityStorage storage3 = PriorityStorage.of(new LimitedStorageImpl(10), 0); sut.addSource(storage1); sut.addSource(storage2); diff --git a/refinedstorage2-storage-api/src/test/java/com/refinedmods/refinedstorage2/api/storage/composite/CompositeStorageImplTest.java b/refinedstorage2-storage-api/src/test/java/com/refinedmods/refinedstorage2/api/storage/composite/CompositeStorageImplTest.java index 92d37d937..f8ccd870a 100644 --- a/refinedstorage2-storage-api/src/test/java/com/refinedmods/refinedstorage2/api/storage/composite/CompositeStorageImplTest.java +++ b/refinedstorage2-storage-api/src/test/java/com/refinedmods/refinedstorage2/api/storage/composite/CompositeStorageImplTest.java @@ -129,9 +129,9 @@ void shouldClearSources() { @Test void shouldRespectPriorityWhenAddingNewSources() { // Arrange - final Storage storage1 = new PrioritizedStorage(20, new LimitedStorageImpl(10)); - final Storage storage2 = new PrioritizedStorage(10, new LimitedStorageImpl(10)); - final Storage storage3 = new PrioritizedStorage(30, new LimitedStorageImpl(10)); + final Storage storage1 = PriorityStorage.of(new LimitedStorageImpl(10), 20); + final Storage storage2 = PriorityStorage.of(new LimitedStorageImpl(10), 10); + final Storage storage3 = PriorityStorage.of(new LimitedStorageImpl(10), 30); // Act sut.addSource(storage1); @@ -154,9 +154,9 @@ void shouldRespectPriorityWhenAddingNewSources() { @Test void shouldRespectPriorityWhenRemovingSources() { // Arrange - final Storage storage1 = new PrioritizedStorage(20, new LimitedStorageImpl(10)); - final Storage storage2 = new PrioritizedStorage(10, new LimitedStorageImpl(10)); - final Storage storage3 = new PrioritizedStorage(30, new LimitedStorageImpl(10)); + final Storage storage1 = PriorityStorage.of(new LimitedStorageImpl(10), 20); + final Storage storage2 = PriorityStorage.of(new LimitedStorageImpl(10), 10); + final Storage storage3 = PriorityStorage.of(new LimitedStorageImpl(10), 30); sut.addSource(storage1); sut.addSource(storage2); @@ -180,8 +180,8 @@ void shouldRespectPriorityWhenRemovingSources() { @Test void shouldOnlyRespectPriorityWhenSortingSourcesExplicitlyWhenChangingPriorityAfterAddingSource() { // Arrange - final PrioritizedStorage storage1 = new PrioritizedStorage(1, new LimitedStorageImpl(10)); - final Storage storage2 = new PrioritizedStorage(2, new LimitedStorageImpl(10)); + final PriorityStorage storage1 = PriorityStorage.of(new LimitedStorageImpl(10), 1); + final Storage storage2 = PriorityStorage.of(new LimitedStorageImpl(10), 2); sut.addSource(storage1); sut.addSource(storage2); diff --git a/refinedstorage2-storage-api/src/test/java/com/refinedmods/refinedstorage2/api/storage/composite/ExtractCompositeStorageImplTest.java b/refinedstorage2-storage-api/src/test/java/com/refinedmods/refinedstorage2/api/storage/composite/ExtractCompositeStorageImplTest.java index 28e9d0343..17aff9ed1 100644 --- a/refinedstorage2-storage-api/src/test/java/com/refinedmods/refinedstorage2/api/storage/composite/ExtractCompositeStorageImplTest.java +++ b/refinedstorage2-storage-api/src/test/java/com/refinedmods/refinedstorage2/api/storage/composite/ExtractCompositeStorageImplTest.java @@ -281,8 +281,8 @@ void shouldNotExtractWithoutAnySourcesPresent() { @Test void shouldRespectPriorityWhenExtracting() { // Arrange - final PrioritizedStorage lowestPriority = new PrioritizedStorage(5, new LimitedStorageImpl(10)); - final PrioritizedStorage highestPriority = new PrioritizedStorage(10, new LimitedStorageImpl(10)); + final PriorityStorage lowestPriority = PriorityStorage.of(new LimitedStorageImpl(10), 5); + final PriorityStorage highestPriority = PriorityStorage.of(new LimitedStorageImpl(10), 10); lowestPriority.insert(A, 5, Action.EXECUTE, EmptyActor.INSTANCE); highestPriority.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); diff --git a/refinedstorage2-storage-api/src/test/java/com/refinedmods/refinedstorage2/api/storage/composite/InsertCompositeStorageImplTest.java b/refinedstorage2-storage-api/src/test/java/com/refinedmods/refinedstorage2/api/storage/composite/InsertCompositeStorageImplTest.java index 4f882bcb2..361c86d0e 100644 --- a/refinedstorage2-storage-api/src/test/java/com/refinedmods/refinedstorage2/api/storage/composite/InsertCompositeStorageImplTest.java +++ b/refinedstorage2-storage-api/src/test/java/com/refinedmods/refinedstorage2/api/storage/composite/InsertCompositeStorageImplTest.java @@ -185,8 +185,8 @@ void shouldNotInsertWithoutAnySourcesPresent() { @Test void shouldRespectPriorityWhenInserting() { // Arrange - final PrioritizedStorage lowestPriority = new PrioritizedStorage(5, new LimitedStorageImpl(10)); - final PrioritizedStorage highestPriority = new PrioritizedStorage(10, new LimitedStorageImpl(10)); + final PriorityStorage lowestPriority = PriorityStorage.of(new LimitedStorageImpl(10), 5); + final PriorityStorage highestPriority = PriorityStorage.of(new LimitedStorageImpl(10), 10); sut.addSource(lowestPriority); sut.addSource(highestPriority);