Skip to content

Commit

Permalink
Drop validation on the properties in equals
Browse files Browse the repository at this point in the history
Drop validation on the properties in equals. This was accidentally
reintroduced during a boy scouting task throughout the project, but this
 was incorrect. The functionality of the multi-tenancy extension expects
  to match on the tenantId ONLY, as properties may differ wildly during
  the flow of the extension as they can be created by the extensions
  and/or users themselves. In those cases, a automated creation and user
   creation of the TenantDescriptor should simply match on the tenantId
   to provide the desired functionality.

#bug/tenant-descriptor-equals-without-properties
  • Loading branch information
smcvb committed Nov 8, 2023
1 parent f988401 commit 19e0b48
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public boolean equals(Object o) {
return false;
}
TenantDescriptor that = (TenantDescriptor) o;
return Objects.equals(tenantId, that.tenantId) && Objects.equals(properties, that.properties);
return Objects.equals(tenantId, that.tenantId);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright (c) 2010-2023. Axon Framework
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.axonframework.extensions.multitenancy.components;

import org.junit.jupiter.api.*;

import java.util.HashMap;

import static org.junit.jupiter.api.Assertions.*;

/**
* Test class validating the {@link TenantDescriptor}.
*
* @author Steven van Beelen
*/
class TenantDescriptorTest {

private static final String TENANT_ID_ONE = "me";
private static final String TENANT_ID_TWO = "you";

@Test
void equalsOnlyValidatesTenantId() {
HashMap<String, String> testPropertiesOne = new HashMap<>();
testPropertiesOne.put("key", "value");
testPropertiesOne.put("key1", "value2");
HashMap<String, String> testPropertiesTwo = new HashMap<>();
testPropertiesOne.put("value", "key");
testPropertiesOne.put("value2", "key1");

TenantDescriptor testSubjectOne = TenantDescriptor.tenantWithId(TENANT_ID_ONE);
TenantDescriptor testSubjectTwo = TenantDescriptor.tenantWithId(TENANT_ID_TWO);
TenantDescriptor testSubjectThree = new TenantDescriptor(TENANT_ID_ONE, testPropertiesOne);
TenantDescriptor testSubjectFour = new TenantDescriptor(TENANT_ID_TWO, testPropertiesTwo);
TenantDescriptor testSubjectFive = new TenantDescriptor(TENANT_ID_ONE, testPropertiesTwo);

// Validate test subject one, only matching on tenant id
assertNotEquals(testSubjectOne, testSubjectTwo);
assertEquals(testSubjectOne, testSubjectThree);
assertNotEquals(testSubjectOne, testSubjectFour);
assertEquals(testSubjectOne, testSubjectFive);
// Validate test subject two, only matching on tenant id
assertNotEquals(testSubjectTwo, testSubjectThree);
assertEquals(testSubjectTwo, testSubjectFour);
assertNotEquals(testSubjectTwo, testSubjectFive);
// Validate test subject three, only matching on tenant id
assertNotEquals(testSubjectThree, testSubjectFour);
assertEquals(testSubjectThree, testSubjectFive);
// Validate test subject four, only matching on tenant id
assertNotEquals(testSubjectFour, testSubjectFive);
}
}

0 comments on commit 19e0b48

Please sign in to comment.