From b35ffc096a02bbfeea3651afbdb3252db82c0087 Mon Sep 17 00:00:00 2001 From: Michael Anstis Date: Wed, 24 Feb 2016 16:14:45 +0000 Subject: [PATCH] BZ1301051: Column values are deleted after changing the operator in a Guided Decision Table --- .../client/utils/DTCellValueUtilities.java | 14 +- .../utils/DTCellValueUtilitiesTest.java | 123 ++++++++++++++++++ 2 files changed, 131 insertions(+), 6 deletions(-) create mode 100644 drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/test/java/org/drools/workbench/screens/guided/dtable/client/utils/DTCellValueUtilitiesTest.java diff --git a/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/main/java/org/drools/workbench/screens/guided/dtable/client/utils/DTCellValueUtilities.java b/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/main/java/org/drools/workbench/screens/guided/dtable/client/utils/DTCellValueUtilities.java index 51824a1ab10..dca3e063246 100644 --- a/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/main/java/org/drools/workbench/screens/guided/dtable/client/utils/DTCellValueUtilities.java +++ b/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/main/java/org/drools/workbench/screens/guided/dtable/client/utils/DTCellValueUtilities.java @@ -214,12 +214,14 @@ public void removeCommaSeparatedValue( DTCellValue52 dcv ) { if ( dcv == null ) { return; } - if ( dcv.getStringValue() == null ) { - return; - } - String[] values = dcv.getStringValue().split( "," ); - if ( values.length > 0 ) { - dcv.setStringValue( values[ 0 ] ); + if ( dcv.getDataType().equals( DataType.DataTypes.STRING ) ) { + if ( dcv.getStringValue() == null ) { + return; + } + String[] values = dcv.getStringValue().split( "," ); + if ( values.length > 0 ) { + dcv.setStringValue( values[ 0 ] ); + } } } diff --git a/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/test/java/org/drools/workbench/screens/guided/dtable/client/utils/DTCellValueUtilitiesTest.java b/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/test/java/org/drools/workbench/screens/guided/dtable/client/utils/DTCellValueUtilitiesTest.java new file mode 100644 index 00000000000..27fcc255732 --- /dev/null +++ b/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/test/java/org/drools/workbench/screens/guided/dtable/client/utils/DTCellValueUtilitiesTest.java @@ -0,0 +1,123 @@ +/* + * Copyright 2016 Red Hat, Inc. and/or its affiliates. + * + * 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.drools.workbench.screens.guided.dtable.client.utils; + +import org.drools.workbench.models.datamodel.oracle.DataType; +import org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52; +import org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; + +import static org.junit.Assert.*; + +@RunWith(MockitoJUnitRunner.class) +public class DTCellValueUtilitiesTest { + + @Mock + private GuidedDecisionTable52 model; + + @Mock + private AsyncPackageDataModelOracle oracle; + + private DTCellValueUtilities utilities; + + @Before + public void setup() { + utilities = new DTCellValueUtilities( model, + oracle ); + } + + @Test + public void testRemoveCommaSeparatedValue() { + DTCellValue52 dcv; + + dcv = new DTCellValue52( 1 ); + utilities.removeCommaSeparatedValue( dcv ); + assertEquals( 1, + dcv.getNumericValue() ); + assertNull( dcv.getBooleanValue() ); + assertNull( dcv.getStringValue() ); + assertNull( dcv.getDateValue() ); + assertEquals( DataType.DataTypes.NUMERIC_INTEGER, + dcv.getDataType() ); + + dcv = new DTCellValue52( 1L ); + utilities.removeCommaSeparatedValue( dcv ); + assertEquals( 1L, + dcv.getNumericValue() ); + assertNull( dcv.getBooleanValue() ); + assertNull( dcv.getStringValue() ); + assertNull( dcv.getDateValue() ); + assertEquals( DataType.DataTypes.NUMERIC_LONG, + dcv.getDataType() ); + + dcv = new DTCellValue52( 1.0 ); + utilities.removeCommaSeparatedValue( dcv ); + assertEquals( 1.0, + dcv.getNumericValue() ); + assertNull( dcv.getBooleanValue() ); + assertNull( dcv.getStringValue() ); + assertNull( dcv.getDateValue() ); + assertEquals( DataType.DataTypes.NUMERIC_DOUBLE, + dcv.getDataType() ); + + dcv = new DTCellValue52( "Fred" ); + utilities.removeCommaSeparatedValue( dcv ); + assertEquals( "Fred", + dcv.getStringValue() ); + assertNull( dcv.getBooleanValue() ); + assertNull( dcv.getNumericValue() ); + assertNull( dcv.getDateValue() ); + assertEquals( DataType.DataTypes.STRING, + dcv.getDataType() ); + + dcv = new DTCellValue52( "Fred,Ginger" ); + utilities.removeCommaSeparatedValue( dcv ); + assertEquals( "Fred", + dcv.getStringValue() ); + assertNull( dcv.getBooleanValue() ); + assertNull( dcv.getNumericValue() ); + assertNull( dcv.getDateValue() ); + assertEquals( DataType.DataTypes.STRING, + dcv.getDataType() ); + + dcv = new DTCellValue52( ",Ginger" ); + utilities.removeCommaSeparatedValue( dcv ); + assertEquals( "", + dcv.getStringValue() ); + assertNull( dcv.getBooleanValue() ); + assertNull( dcv.getNumericValue() ); + assertNull( dcv.getDateValue() ); + assertEquals( DataType.DataTypes.STRING, + dcv.getDataType() ); + + dcv = new DTCellValue52( "Fred," ); + utilities.removeCommaSeparatedValue( dcv ); + assertEquals( "Fred", + dcv.getStringValue() ); + assertNull( dcv.getBooleanValue() ); + assertNull( dcv.getNumericValue() ); + assertNull( dcv.getDateValue() ); + assertEquals( DataType.DataTypes.STRING, + dcv.getDataType() ); + } + +}