Permalink
Browse files

Merge pull request #903 from canoo/null-qualifier

Fix if qualifier bound value set to null
  • Loading branch information...
hendrikebbers committed Apr 17, 2018
2 parents f8583c7 + 0ac494e commit dcf04183905759f343657a4a792377b6c2ea111d
@@ -62,6 +62,42 @@ public void testQualifier1() {
assertSubBeanValue(qualifierTestSubBeanTwo, 42, true, "Test1");
}
@Test
public void testQualifier1With2Controllers() {
//given:
final ControllerUnderTest<QualifierTestBean> controller2 = createController(QUALIFIER_CONTROLLER_NAME);
final QualifierTestSubBean qualifierTestSubBeanOne = controller.getModel().getQualifierTestSubBeanOneValue();
final QualifierTestSubBean qualifierTestSubBeanTwo = controller2.getModel().getQualifierTestSubBeanOneValue();
//when:
setSubBeanValue(qualifierTestSubBeanOne, 42, true, "Test1");
//then:
assertSubBeanValue(qualifierTestSubBeanOne, 42, true, "Test1");
assertSubBeanValue(qualifierTestSubBeanTwo, 42, true, "Test1");
controller2.destroy();
}
@Test
public void testQualifier2With2Controllers() {
//given:
final ControllerUnderTest<QualifierTestBean> controller2 = createController(QUALIFIER_CONTROLLER_NAME);
final QualifierTestSubBean qualifierTestSubBeanOne = controller.getModel().getQualifierTestSubBeanOneValue();
final QualifierTestSubBean qualifierTestSubBeanTwo = controller2.getModel().getQualifierTestSubBeanOneValue();
//when:
setSubBeanValue(qualifierTestSubBeanTwo, 44, true, "Test2");
//then:
assertSubBeanValue(qualifierTestSubBeanOne, 44, true, "Test2");
assertSubBeanValue(qualifierTestSubBeanTwo, 44, true, "Test2");
controller2.destroy();
}
@Test
public void testQualifier2() {
//given:
@@ -77,6 +113,25 @@ public void testQualifier2() {
assertSubBeanValue(qualifierTestSubBeanTwo, 44, true, "Test2");
}
@Test
public void testQualifierWithNullValue() {
//given:
final QualifierTestSubBean qualifierTestSubBeanOne = controller.getModel().getQualifierTestSubBeanOneValue();
final QualifierTestSubBean qualifierTestSubBeanTwo = controller.getModel().getQualifierTestSubBeanTwoValue();
//when:
setSubBeanValue(qualifierTestSubBeanOne, 42, true, "Test1");
setSubBeanValue(qualifierTestSubBeanOne, 42, true, null);
controller.invoke(DUMMY_ACTION);
//then:
assertSubBeanValue(qualifierTestSubBeanOne, 42, true, null);
assertSubBeanValue(qualifierTestSubBeanTwo, 42, true, null);
}
@Test
public void testQualifierUnbind() {
//given:
@@ -95,6 +150,25 @@ public void testQualifierUnbind() {
}
@Test
public void testQualifierUnbindWith2Controllers() {
//given:
final ControllerUnderTest<QualifierTestBean> controller2 = createController(QUALIFIER_CONTROLLER_NAME);
final QualifierTestSubBean qualifierTestSubBeanOne = controller.getModel().getQualifierTestSubBeanOneValue();
final QualifierTestSubBean qualifierTestSubBeanTwo = controller2.getModel().getQualifierTestSubBeanOneValue();
//when:
setSubBeanValue(qualifierTestSubBeanOne, 42, true, "Test1");
controller.invoke(UNBIND_ACTION);
setSubBeanValue(qualifierTestSubBeanOne, 44, false, "Test2");
//then:
assertSubBeanValue(qualifierTestSubBeanOne, 44, false, "Test2");
assertSubBeanValue(qualifierTestSubBeanTwo, 42, true, "Test1");
controller2.destroy();
}
@Test
public void testQualifierNotBound() {
//given:
@@ -112,6 +186,25 @@ public void testQualifierNotBound() {
}
@Test
public void testQualifierNotBoundWith2Controllers() {
//given:
final ControllerUnderTest<QualifierTestBean> controller2 = createController(QUALIFIER_CONTROLLER_NAME);
final QualifierTestSubBean qualifierTestSubBeanOne = controller.getModel().getQualifierTestSubBeanOneValue();
final QualifierTestSubBean qualifierTestSubBeanTwo = controller2.getModel().getQualifierTestSubBeanOneValue();
//when:
controller.invoke(UNBIND_ACTION);
setSubBeanValue(qualifierTestSubBeanOne, 42, true, "Test1");
controller.invoke(DUMMY_ACTION);
//then:
assertSubBeanValue(qualifierTestSubBeanOne, 42, true, "Test1");
assertSubBeanValue(qualifierTestSubBeanTwo, null, null, null);
controller2.destroy();
}
@Test
public void testQualifierRebind() {
//given:
@@ -128,6 +221,26 @@ public void testQualifierRebind() {
assertSubBeanValue(qualifierTestSubBeanTwo, 42, true, "Test1");
}
@Test
public void testQualifierRebindWith2Controllers() {
//given:
final ControllerUnderTest<QualifierTestBean> controller2 = createController(QUALIFIER_CONTROLLER_NAME);
final QualifierTestSubBean qualifierTestSubBeanOne = controller.getModel().getQualifierTestSubBeanOneValue();
final QualifierTestSubBean qualifierTestSubBeanTwo = controller2.getModel().getQualifierTestSubBeanOneValue();
//when:
controller.invoke(UNBIND_ACTION);
setSubBeanValue(qualifierTestSubBeanTwo, 42, true, "Test1");
controller.invoke(BIND_ACTION);
//then:
assertSubBeanValue(qualifierTestSubBeanOne, null, null, null);
assertSubBeanValue(qualifierTestSubBeanTwo, 42, true, "Test1");
controller2.destroy();
}
@Test
public void testQualifierChangeAfterRebind() {
//given:
@@ -145,6 +258,27 @@ public void testQualifierChangeAfterRebind() {
assertSubBeanValue(qualifierTestSubBeanTwo, 44, false, "Test2");
}
@Test
public void testQualifierChangeAfterRebindWith2Controllers() {
//given:
final ControllerUnderTest<QualifierTestBean> controller2 = createController(QUALIFIER_CONTROLLER_NAME);
final QualifierTestSubBean qualifierTestSubBeanOne = controller.getModel().getQualifierTestSubBeanOneValue();
final QualifierTestSubBean qualifierTestSubBeanTwo = controller2.getModel().getQualifierTestSubBeanOneValue();
//when:
controller.invoke(UNBIND_ACTION);
setSubBeanValue(qualifierTestSubBeanOne, 42, true, "Test1");
controller.invoke(BIND_ACTION);
setSubBeanValue(qualifierTestSubBeanTwo, 44, false, "Test2");
//then:
assertSubBeanValue(qualifierTestSubBeanOne, 44, false, "Test2");
assertSubBeanValue(qualifierTestSubBeanTwo, 44, false, "Test2");
controller2.destroy();
}
private void setSubBeanValue(final QualifierTestSubBean qualifierTestSubBean, final int intValue, final boolean booleanValue, final String stringValue) {
qualifierTestSubBean.setBooleanValue(booleanValue);
qualifierTestSubBean.setStringValue(stringValue);
@@ -58,6 +58,65 @@ public void testQualifier1(String containerType, String endpoint) {
}
}
@Test(dataProvider = ENDPOINTS_DATAPROVIDER, description = "Test if QualifierTestSubBeanTwo is sync when updating QualifierTestSubBean")
public void testQualifier1With2Controllers(String containerType, String endpoint) {
try {
final ClientContext context = connect(endpoint);
final ControllerProxy<QualifierTestBean> controller1 = createController(context, QUALIFIER_CONTROLLER_NAME);
final ControllerProxy<QualifierTestBean> controller2 = createController(context, QUALIFIER_CONTROLLER_NAME);
//given:
final QualifierTestSubBean qualifierTestSubBeanOne = controller1.getModel().getQualifierTestSubBeanOneValue();
final QualifierTestSubBean qualifierTestSubBeanTwo = controller2.getModel().getQualifierTestSubBeanOneValue();
//when:
setSubBeanValue(qualifierTestSubBeanOne, 42, true, "Test1");
invoke(controller1, DUMMY_ACTION, containerType);
//then:
assertSubBeanValue(qualifierTestSubBeanOne, 42, true, "Test1");
assertSubBeanValue(qualifierTestSubBeanTwo, 42, true, "Test1");
//Destroy and Disconnect Controller
destroy(controller1, endpoint);
destroy(controller2, endpoint);
disconnect(context, endpoint);
} catch (Exception e) {
Assert.fail("Can not create controller for " + containerType, e);
}
}
@Test(dataProvider = ENDPOINTS_DATAPROVIDER, description = "Test if QualifierTestSubBeanTwo is sync when updating QualifierTestSubBean")
public void testQualifierNullValue(String containerType, String endpoint) {
try {
final ClientContext context = connect(endpoint);
final ControllerProxy<QualifierTestBean> controller = createController(context, QUALIFIER_CONTROLLER_NAME);
//given:
final QualifierTestSubBean qualifierTestSubBeanOne = controller.getModel().getQualifierTestSubBeanOneValue();
final QualifierTestSubBean qualifierTestSubBeanTwo = controller.getModel().getQualifierTestSubBeanTwoValue();
//when:
setSubBeanValue(qualifierTestSubBeanOne, 42, true, "Test1");
setSubBeanValue(qualifierTestSubBeanOne, 42, true, null);
invoke(controller, DUMMY_ACTION, containerType);
//then:
assertSubBeanValue(qualifierTestSubBeanOne, 42, true, null);
assertSubBeanValue(qualifierTestSubBeanTwo, 42, true, null);
//Destroy and Disconnect Controller
destroy(controller, endpoint);
disconnect(context, endpoint);
} catch (Exception e) {
Assert.fail("Can not create controller for " + containerType, e);
}
}
@Test(dataProvider = ENDPOINTS_DATAPROVIDER, description = "Test if QualifierTestSubBean is sync when updating QualifierTestSubBeanTwo")
public void testQualifier2(String containerType, String endpoint) {
try {
@@ -115,6 +174,36 @@ public void testQualifierUnbind(String containerType, String endpoint) {
}
}
@Test(dataProvider = ENDPOINTS_DATAPROVIDER, description = "Test Qualifier Unbind")
public void testQualifierUnbindWith2Controlers(String containerType, String endpoint) {
try {
final ClientContext context = connect(endpoint);
final ControllerProxy<QualifierTestBean> controller1 = createController(context, QUALIFIER_CONTROLLER_NAME);
final ControllerProxy<QualifierTestBean> controller2 = createController(context, QUALIFIER_CONTROLLER_NAME);
//given:
final QualifierTestSubBean qualifierTestSubBeanOne = controller1.getModel().getQualifierTestSubBeanOneValue();
final QualifierTestSubBean qualifierTestSubBeanTwo = controller2.getModel().getQualifierTestSubBeanOneValue();
//when:
setSubBeanValue(qualifierTestSubBeanOne, 42, true, "Test1");
invoke(controller1, UNBIND_ACTION, containerType);
setSubBeanValue(qualifierTestSubBeanOne, 44, false, "Test2");
//then:
assertSubBeanValue(qualifierTestSubBeanOne, 44, false, "Test2");
assertSubBeanValue(qualifierTestSubBeanTwo, 42, true, "Test1");
//Destroy and Disconnect Controller
destroy(controller1, endpoint);
destroy(controller2, endpoint);
disconnect(context, endpoint);
} catch (Exception e) {
Assert.fail("Can not create controller for " + containerType, e);
}
}
@Test(dataProvider = ENDPOINTS_DATAPROVIDER, description = "Test Qualifier Not Bound")
public void testQualifierNotBound(String containerType, String endpoint) {
try {
@@ -143,6 +232,36 @@ public void testQualifierNotBound(String containerType, String endpoint) {
}
}
@Test(dataProvider = ENDPOINTS_DATAPROVIDER, description = "Test Qualifier Not Bound")
public void testQualifierNotBoundWith2Controllers(String containerType, String endpoint) {
try {
final ClientContext context = connect(endpoint);
final ControllerProxy<QualifierTestBean> controller1 = createController(context, QUALIFIER_CONTROLLER_NAME);
final ControllerProxy<QualifierTestBean> controller2 = createController(context, QUALIFIER_CONTROLLER_NAME);
//given:
final QualifierTestSubBean qualifierTestSubBeanOne = controller1.getModel().getQualifierTestSubBeanOneValue();
final QualifierTestSubBean qualifierTestSubBeanTwo = controller2.getModel().getQualifierTestSubBeanOneValue();
//when:
invoke(controller1, UNBIND_ACTION, containerType);
setSubBeanValue(qualifierTestSubBeanOne, 42, true, "Test1");
invoke(controller1, DUMMY_ACTION, containerType);
//then:
assertSubBeanValue(qualifierTestSubBeanOne, 42, true, "Test1");
assertSubBeanValue(qualifierTestSubBeanTwo, null, null, null);
//Destroy and Disconnect Controller
destroy(controller1, endpoint);
destroy(controller2, endpoint);
disconnect(context, endpoint);
} catch (Exception e) {
Assert.fail("Can not create controller for " + containerType, e);
}
}
@Test(dataProvider = ENDPOINTS_DATAPROVIDER, description = "Test Qualifier Rebind")
public void testQualifierRebind(String containerType, String endpoint) {
try {
@@ -171,6 +290,36 @@ public void testQualifierRebind(String containerType, String endpoint) {
}
}
@Test(dataProvider = ENDPOINTS_DATAPROVIDER, description = "Test Qualifier Rebind")
public void testQualifierRebindWith2Controllers(String containerType, String endpoint) {
try {
final ClientContext context = connect(endpoint);
final ControllerProxy<QualifierTestBean> controller1 = createController(context, QUALIFIER_CONTROLLER_NAME);
final ControllerProxy<QualifierTestBean> controller2 = createController(context, QUALIFIER_CONTROLLER_NAME);
//given:
final QualifierTestSubBean qualifierTestSubBeanOne = controller1.getModel().getQualifierTestSubBeanOneValue();
final QualifierTestSubBean qualifierTestSubBeanTwo = controller2.getModel().getQualifierTestSubBeanOneValue();
//when:
invoke(controller1, UNBIND_ACTION, containerType);
setSubBeanValue(qualifierTestSubBeanTwo, 42, true, "Test1");
invoke(controller1, BIND_ACTION, containerType);
//then:
assertSubBeanValue(qualifierTestSubBeanOne, null, null, null);
assertSubBeanValue(qualifierTestSubBeanTwo, 42, true, "Test1");
//Destroy and Disconnect Controller
destroy(controller1, endpoint);
destroy(controller2, endpoint);
disconnect(context, endpoint);
} catch (Exception e) {
Assert.fail("Can not create controller for " + containerType, e);
}
}
@Test(dataProvider = ENDPOINTS_DATAPROVIDER, description = "Test Qualifier Change After Rebind")
public void testQualifierChangeAfterRebind(String containerType, String endpoint) {
try {
@@ -23,6 +23,7 @@
import org.apiguardian.api.API;
import java.util.List;
import java.util.Objects;
import static org.apiguardian.api.API.Status.INTERNAL;
@@ -69,7 +70,7 @@ public void setValue(final Object newValue) {
continue;
}
if (newValue == null && sameQualified.getValue() != null || newValue != null && sameQualified.getValue() == null || !newValue.equals(sameQualified.getValue())) {
if (!Objects.equals(newValue, sameQualified.getValue())) {
sameQualified.setValue(newValue);
}
}

0 comments on commit dcf0418

Please sign in to comment.