View Javadoc
1   /**
2    * Copyright 2005-2016 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.uif.util;
17  
18  import org.junit.Before;
19  import org.junit.Ignore;
20  import org.junit.Test;
21  import org.kuali.rice.core.api.config.property.Config;
22  import org.kuali.rice.core.api.config.property.ConfigContext;
23  import org.kuali.rice.krad.uif.component.Component;
24  import org.kuali.rice.krad.uif.component.ComponentBase;
25  import org.kuali.rice.krad.uif.component.ReferenceCopy;
26  import org.kuali.rice.krad.uif.container.CollectionGroup;
27  import org.kuali.rice.krad.uif.container.CollectionGroupBase;
28  import org.kuali.rice.krad.uif.control.CheckboxControl;
29  import org.kuali.rice.krad.uif.element.Action;
30  import org.kuali.rice.krad.uif.element.BreadcrumbItem;
31  import org.kuali.rice.krad.uif.element.Label;
32  import org.kuali.rice.krad.uif.field.DataField;
33  import org.kuali.rice.krad.uif.field.DataFieldBase;
34  import org.kuali.rice.krad.uif.field.FieldBase;
35  import org.kuali.rice.krad.uif.field.InputField;
36  import org.kuali.rice.krad.uif.field.InputFieldBase;
37  import org.kuali.rice.krad.uif.widget.Tooltip;
38  import org.kuali.rice.krad.util.KRADConstants;
39  
40  import java.lang.reflect.Field;
41  import java.lang.reflect.ParameterizedType;
42  import java.util.ArrayList;
43  import java.util.Arrays;
44  import java.util.HashMap;
45  import java.util.HashSet;
46  import java.util.List;
47  import java.util.Map;
48  import java.util.Set;
49  
50  import static org.junit.Assert.assertEquals;
51  import static org.junit.Assert.assertTrue;
52  
53  /**
54   * ComponentUtilsTest tests various ComponentUtils methods
55   *
56   * @author Kuali Rice Team (rice.collab@kuali.org)
57   */
58  public class ComponentUtilsTest {
59  
60      private String componentId;
61      private Component component;
62  
63      @Before
64      public void setup() {
65          component = new InputFieldBase();
66          componentId = "field1";
67          component.setId(componentId);
68      }
69  
70      // Initialization methods
71      private CollectionGroup initializeCollectionGroup() {
72          CollectionGroupBase collectionGroup = new CollectionGroupBase();
73          collectionGroup = (CollectionGroupBase) initializeComponentBase(collectionGroup);
74  
75          DataField field1 = initializeDataField();
76          DataField field2 = initializeDataField();
77          List<DataField> fields = new ArrayList<DataField>();
78          fields.add(field1);
79          fields.add(field2);
80          collectionGroup.setAddLineItems(fields);
81  
82          Action action1 = new Action();
83          action1 = (Action) initializeComponentBase(action1);
84          action1.setActionLabel("Action Label");
85          action1.setActionScript("<script>Action script</script>");
86  
87          Action action2 = new Action();
88          action2 = (Action) initializeComponentBase(action2);
89          action2.setActionLabel("Action Label 2");
90          action2.setActionScript("<script>Action script 2</script>");
91          List<Action> addLineActions = new ArrayList<Action>();
92          addLineActions.add(action1);
93          addLineActions.add(action2);
94          collectionGroup.setAddLineActions(addLineActions);
95  
96          return collectionGroup;
97      }
98  
99      private FieldBase initializeFieldBase() {
100         FieldBase fieldBase = new FieldBase();
101         fieldBase = (FieldBase) initializeComponentBase(fieldBase);
102         fieldBase.setShortLabel("Label");
103 
104         return fieldBase;
105     }
106 
107     private DataField initializeDataField() {
108         DataFieldBase dataField = new DataFieldBase();
109         dataField = (DataFieldBase) initializeComponentBase(dataField);
110         dataField.setAddHiddenWhenReadOnly(true);
111 
112         List<String> additionalHiddenPropertyNames = new ArrayList<String>();
113         additionalHiddenPropertyNames.add("HiddenA");
114         additionalHiddenPropertyNames.add("HiddenB");
115         additionalHiddenPropertyNames.add("HiddenC");
116         dataField.setAdditionalHiddenPropertyNames(additionalHiddenPropertyNames);
117 
118         dataField.setApplyMask(true);
119         dataField.setDefaultValue("default");
120         dataField.setDictionaryAttributeName("DictionaryName");
121         dataField.setDictionaryObjectEntry("DictionaryObjectEntry");
122         dataField.setEscapeHtmlInPropertyValue(true);
123         dataField.setForcedValue("Forced");
124         dataField.setMultiLineReadOnlyDisplay(true);
125 
126         return dataField;
127     }
128 
129     private ComponentBase initializeComponentBase(ComponentBase componentBase) {
130         List<String> additionalComponentsToRefresh = new ArrayList<String>();
131         additionalComponentsToRefresh.add("A");
132         additionalComponentsToRefresh.add("B");
133         additionalComponentsToRefresh.add("C");
134         componentBase.setAdditionalComponentsToRefresh(additionalComponentsToRefresh);
135 
136         List<String> additionalCssClasses = new ArrayList<String>();
137         additionalCssClasses.add("Class1");
138         additionalCssClasses.add("Class2");
139         additionalCssClasses.add("Class3");
140         componentBase.setAdditionalCssClasses(additionalCssClasses);
141 
142         componentBase.setAlign("right");
143 
144         List<String> cellCssClasses = new ArrayList<String>();
145         cellCssClasses.add("CellClass1");
146         cellCssClasses.add("CellClass2");
147         cellCssClasses.add("CellClass3");
148         componentBase.setWrapperCssClasses(cellCssClasses);
149 
150         componentBase.setWrapperStyle("Style1");
151         componentBase.setCellWidth("20px");
152         componentBase.setColSpan(2);
153         componentBase.setConditionalRefresh("Refresh");
154 
155         List<String> cssClasses = new ArrayList<String>();
156         cssClasses.add("CssClass1");
157         cssClasses.add("CssClass2");
158         cssClasses.add("CssClass3");
159         componentBase.setCssClasses(cssClasses);
160 
161         Map<String, String> dataAttributes = new HashMap<String, String>();
162         dataAttributes.put("One", "A");
163         dataAttributes.put("Two", "B");
164         dataAttributes.put("Three", "C");
165         componentBase.setDataAttributes(dataAttributes);
166 
167         componentBase.setFinalizeMethodToCall("methodA");
168         componentBase.setMethodToCallOnRefresh("methodB");
169         componentBase.setOnBlurScript("onblurscript");
170         componentBase.setOnChangeScript("onchangescript");
171         componentBase.setOnClickScript("onclickscript");
172         componentBase.setOnCloseScript("onclosescript");
173         componentBase.setOnDblClickScript("ondblclickscript");
174         componentBase.setOnDocumentReadyScript("ondocreadyscript");
175         componentBase.setOnFocusScript("onfocusscript");
176         componentBase.setOnKeyDownScript("onkeydownscript");
177         componentBase.setOnKeyPressScript("onkeypressscript");
178         componentBase.setOnKeyUpScript("onkeyupscript");
179         componentBase.setOnLoadScript("onloadscript");
180         componentBase.setOnMouseDownScript("onmousedownscript");
181         componentBase.setOnMouseMoveScript("onmousemovescript");
182         componentBase.setOnMouseOutScript("onmouseoutscript");
183         componentBase.setOnMouseOverScript("onmouseoverscript");
184         componentBase.setOnMouseUpScript("onmouseupscript");
185         componentBase.setOnSubmitScript("onsubmitscript");
186         componentBase.setOnUnloadScript("onunloadscript");
187         componentBase.setOrder(5);
188         componentBase.setPostRenderContent("PostRenderContent");
189         componentBase.setPreRenderContent("PreRenderContent");
190         componentBase.setProgressiveRender("ProgressiveRender");
191         componentBase.setReadOnly(false);
192         componentBase.setRefreshedByAction(false);
193         componentBase.setRefreshTimer(12);
194 
195         List<String> refreshWhenChangedPropertyNames = new ArrayList<String>();
196         refreshWhenChangedPropertyNames.add("property1");
197         refreshWhenChangedPropertyNames.add("property2");
198         refreshWhenChangedPropertyNames.add("property3");
199         componentBase.setRefreshWhenChangedPropertyNames(refreshWhenChangedPropertyNames);
200 
201         componentBase.setRenderedHtmlOutput("<output>");
202         componentBase.setRowSpan(3);
203         componentBase.setStyle("slick");
204         componentBase.setTemplate("TemplateA");
205         componentBase.setTemplateName("TemplateName");
206 
207         Map<String, String> templateOptions = new HashMap<String, String>();
208         templateOptions.put("Option1", "Value1");
209         templateOptions.put("Option1", "Value2");
210         templateOptions.put("Option1", "Value3");
211         componentBase.setTemplateOptions(templateOptions);
212 
213         componentBase.setTemplateOptionsJSString("OptionsJS");
214         componentBase.setTitle("Title");
215         componentBase.setValign("middle");
216         componentBase.setWidth("30px");
217 
218         return componentBase;
219     }
220 
221     // End of Initialization methods
222 
223     /**
224      * test that {@link ComponentUtils#updateIdWithSuffix} works ok
225      */
226     @Test
227     public void testUpdateIdWithSuffix() {
228         ComponentUtils.updateIdWithSuffix(component, null);
229         assertTrue(component.getId().equalsIgnoreCase(componentId));
230 
231         String suffix = "_field";
232         ComponentUtils.updateIdWithSuffix(component, suffix);
233         assertTrue(component.getId().equalsIgnoreCase(componentId + suffix));
234     }
235 
236     @Test
237     /**
238      * test {@link ComponentUtils#copyUsingCloning} using a FieldBase object
239      */
240     public void testCopyUsingCloningWithFieldBaseSucceeds() {
241         FieldBase fieldBaseOriginal = initializeFieldBase();
242         FieldBase fieldBaseCopy = CopyUtils.copy(fieldBaseOriginal);
243 
244         assertTrue(ComponentCopyPropertiesMatch(fieldBaseOriginal, fieldBaseCopy));
245         assertTrue(fieldBaseOriginal.getShortLabel().equals(fieldBaseCopy.getShortLabel()));
246     }
247 
248     @Test
249     /**
250      * test {@link ComponentUtils#copyUsingCloning} using a DataField object
251      */
252     public void testCopyUsingCloningWithDataFieldSucceeds() {
253         DataField dataFieldOriginal = initializeDataField();
254 
255         DataField dataFieldCopy = CopyUtils.copy(dataFieldOriginal);
256         assertTrue(ComponentCopyPropertiesMatch(dataFieldOriginal, dataFieldCopy));
257     }
258 
259     /**
260      * test {@link ComponentUtils#copyUsingCloning} using a CollectionGroup object
261      */
262     @Test
263     public void testCopyUsingCloningWithSimpleCollectionGroupSucceeds() {
264         CollectionGroup collectionGroupOriginal = initializeCollectionGroup();
265         CollectionGroup collectionGroupCopy = CopyUtils.copy(collectionGroupOriginal);
266 
267         assertTrue(ComponentCopyPropertiesMatch(collectionGroupOriginal, collectionGroupCopy));
268 
269         for (int i = 0; i < collectionGroupOriginal.getAddLineItems().size(); i++) {
270             assertTrue(ComponentCopyPropertiesMatch(
271                     CopyUtils.unwrap((ComponentBase) collectionGroupOriginal.getAddLineItems().get(i)),
272                     CopyUtils.unwrap((ComponentBase) collectionGroupCopy.getAddLineItems().get(i))));
273         }
274 
275         for (int i = 0; i < collectionGroupOriginal.getAddLineActions().size(); i++) {
276             assertTrue(ComponentCopyPropertiesMatch(
277                     CopyUtils.unwrap((Component) collectionGroupOriginal.getAddLineActions().get(i)),
278                     CopyUtils.unwrap((Component) collectionGroupCopy.getAddLineActions().get(i))));
279         }
280     }
281 
282     private boolean ComponentCopyPropertiesMatch(Component originalComponent, Component copiedComponent) {
283         boolean result = true;
284 
285         List<String> missingComponentsToRefresh = originalComponent.getAdditionalComponentsToRefresh();
286         if (missingComponentsToRefresh != null) {
287             missingComponentsToRefresh = new ArrayList<String>(missingComponentsToRefresh);
288             missingComponentsToRefresh.removeAll(copiedComponent.getAdditionalComponentsToRefresh());
289             if (!missingComponentsToRefresh.isEmpty()) {
290                 result = false;
291             }
292         }
293 
294         List<String> missingAdditionalCssClasses = new ArrayList<String>(originalComponent.getAdditionalCssClasses());
295         missingAdditionalCssClasses.removeAll(copiedComponent.getAdditionalCssClasses());
296         if (!missingAdditionalCssClasses.isEmpty()) {
297             result = false;
298         }
299 
300         if (!originalComponent.getAlign().equals(copiedComponent.getAlign())) {
301             result = false;
302         }
303 
304         List<String> missingCellCssClasses = originalComponent.getWrapperCssClasses();
305         if (missingCellCssClasses != null) {
306             missingCellCssClasses.removeAll(copiedComponent.getWrapperCssClasses());
307             if (!missingCellCssClasses.isEmpty()) {
308                 result = false;
309             }
310         }
311 
312         if (!originalComponent.getWrapperStyle().equals(copiedComponent.getWrapperStyle())) {
313             result = false;
314         }
315         if (!originalComponent.getCellWidth().equals(copiedComponent.getCellWidth())) {
316             result = false;
317         }
318         if (originalComponent.getColSpan() != copiedComponent.getColSpan()) {
319             result = false;
320         }
321         if (!originalComponent.getConditionalRefresh().equals(copiedComponent.getConditionalRefresh())) {
322             result = false;
323         }
324 
325         List<String> missingCssClasses = new ArrayList<String>(originalComponent.getCssClasses());
326         missingCssClasses.removeAll(copiedComponent.getCssClasses());
327         if (!missingCssClasses.isEmpty()) {
328             result = false;
329         }
330 
331         Map<String, String> origDataAttributes = originalComponent.getDataAttributes();
332         if (origDataAttributes != null) {
333             Set<String> dataAttributes = new HashSet<String>(origDataAttributes.values());
334             dataAttributes.removeAll(copiedComponent.getDataAttributes().values());
335             if (!dataAttributes.isEmpty()) {
336                 result = false;
337             }
338         }
339 
340         if (!originalComponent.getFinalizeMethodToCall().equals(copiedComponent.getFinalizeMethodToCall())) {
341             result = false;
342         }
343         if (originalComponent instanceof ComponentBase &&  copiedComponent instanceof ComponentBase){
344             if (! (((ComponentBase)originalComponent).getMethodToCallOnRefresh().equals(((ComponentBase)copiedComponent).getMethodToCallOnRefresh()))) {
345                 result = false;
346             }
347         } else {
348             result = false;
349         }
350         if (!originalComponent.getOnBlurScript().equals(copiedComponent.getOnBlurScript())) {
351             result = false;
352         }
353         if (!originalComponent.getOnChangeScript().equals(copiedComponent.getOnChangeScript())) {
354             result = false;
355         }
356         if (!originalComponent.getOnClickScript().equals(copiedComponent.getOnClickScript())) {
357             result = false;
358         }
359         if (!originalComponent.getOnCloseScript().equals(copiedComponent.getOnCloseScript())) {
360             result = false;
361         }
362         if (!originalComponent.getOnDblClickScript().equals(copiedComponent.getOnDblClickScript())) {
363             result = false;
364         }
365         if (!originalComponent.getOnDocumentReadyScript().equals(copiedComponent.getOnDocumentReadyScript())) {
366             result = false;
367         }
368         if (!originalComponent.getOnFocusScript().equals(copiedComponent.getOnFocusScript())) {
369             result = false;
370         }
371         if (!originalComponent.getOnKeyDownScript().equals(copiedComponent.getOnKeyDownScript())) {
372             result = false;
373         }
374         if (!originalComponent.getOnKeyPressScript().equals(copiedComponent.getOnKeyPressScript())) {
375             result = false;
376         }
377         if (!originalComponent.getOnKeyUpScript().equals(copiedComponent.getOnKeyUpScript())) {
378             result = false;
379         }
380         if (!originalComponent.getOnLoadScript().equals(copiedComponent.getOnLoadScript())) {
381             result = false;
382         }
383         if (!originalComponent.getOnMouseDownScript().equals(copiedComponent.getOnMouseDownScript())) {
384             result = false;
385         }
386         if (!originalComponent.getOnMouseMoveScript().equals(copiedComponent.getOnMouseMoveScript())) {
387             result = false;
388         }
389         if (!originalComponent.getOnMouseOutScript().equals(copiedComponent.getOnMouseOutScript())) {
390             result = false;
391         }
392         if (!originalComponent.getOnMouseOverScript().equals(copiedComponent.getOnMouseOverScript())) {
393             result = false;
394         }
395         if (!originalComponent.getOnMouseUpScript().equals(copiedComponent.getOnMouseUpScript())) {
396             result = false;
397         }
398         if (!originalComponent.getOnSubmitScript().equals(copiedComponent.getOnSubmitScript())) {
399             result = false;
400         }
401         if (!originalComponent.getOnUnloadScript().equals(copiedComponent.getOnUnloadScript())) {
402             result = false;
403         }
404         if (originalComponent.getOrder() != copiedComponent.getOrder()) {
405             result = false;
406         }
407         if (!originalComponent.getPostRenderContent().equals(copiedComponent.getPostRenderContent())) {
408             result = false;
409         }
410         if (!originalComponent.getPreRenderContent().equals(copiedComponent.getPreRenderContent())) {
411             result = false;
412         }
413         if (!originalComponent.getProgressiveRender().equals(copiedComponent.getProgressiveRender())) {
414             result = false;
415         }
416         if (originalComponent.getRequired() != copiedComponent.getRequired()) {
417             result = false;
418         }
419         if (originalComponent.getRefreshTimer() != copiedComponent.getRefreshTimer()) {
420             result = false;
421         }
422 
423         List<String> missingRefreshWhenChangedPropertyNames = originalComponent.getRefreshWhenChangedPropertyNames();
424         if (missingRefreshWhenChangedPropertyNames != null) {
425             missingRefreshWhenChangedPropertyNames = new ArrayList<String>(missingRefreshWhenChangedPropertyNames);
426             missingRefreshWhenChangedPropertyNames.removeAll(copiedComponent.getRefreshWhenChangedPropertyNames());
427             if (!missingRefreshWhenChangedPropertyNames.isEmpty()) {
428                 result = false;
429             }
430         }
431 
432         if (!originalComponent.getRenderedHtmlOutput().equals(copiedComponent.getRenderedHtmlOutput())) {
433             result = false;
434         }
435         if (originalComponent.getRowSpan() != copiedComponent.getRowSpan()) {
436             result = false;
437         }
438         if (!originalComponent.getStyle().equals(copiedComponent.getStyle())) {
439             result = false;
440         }
441         if (!originalComponent.getTemplate().equals(copiedComponent.getTemplate())) {
442             result = false;
443         }
444         if (!originalComponent.getTemplateName().equals(copiedComponent.getTemplateName())) {
445             result = false;
446         }
447 
448         Map<String, String> origTemplateOptions = originalComponent.getTemplateOptions();
449         if (origTemplateOptions != null) {
450             Set<String> templateOptions = new HashSet<String>(origTemplateOptions.values());
451             Map<String, String> copiedTemplateOptions = copiedComponent.getTemplateOptions();
452 
453             if (copiedTemplateOptions != null) {
454                 templateOptions.removeAll(copiedTemplateOptions.values());
455             }
456 
457             if (!templateOptions.isEmpty()) {
458                 result = false;
459             }
460         }
461 
462         if (!originalComponent.getTemplateOptionsJSString().equals(copiedComponent.getTemplateOptionsJSString())) {
463             result = false;
464         }
465         if (!originalComponent.getTitle().equals(copiedComponent.getTitle())) {
466             result = false;
467         }
468         if (!originalComponent.getValign().equals(copiedComponent.getValign())) {
469             result = false;
470         }
471         if (!originalComponent.getWidth().equals(copiedComponent.getWidth())) {
472             result = false;
473         }
474 
475         return result;
476     }
477 
478     /**
479      * Test {@link ContextUtils#cleanContextDeep} using a BreadcrumbItem object
480      */
481     @Test
482     public void testCleanContextDeap() {
483         Map<String, Object> context = new HashMap<String, Object>();
484         context.put("contextkey", "value");
485         context.put("contextkey2", "value2");
486 
487         BreadcrumbItem breadcrumbItem = new BreadcrumbItem();
488         breadcrumbItem.setContext(context);
489 
490         InputField inputField = new InputFieldBase();
491         inputField.setContext(context);
492 
493         Label fieldLabel = new Label();
494         fieldLabel.setContext(context);
495 
496         Tooltip labelTootlip = new Tooltip();
497         labelTootlip.setContext(context);
498         fieldLabel.setToolTip(labelTootlip);
499 
500         inputField.setFieldLabel(fieldLabel);
501 
502         breadcrumbItem.setSiblingBreadcrumbComponent(inputField);
503 
504         Tooltip tooltip = new Tooltip();
505         tooltip.setContext(context);
506 
507         breadcrumbItem.setToolTip(tooltip);
508 
509         ContextUtils.cleanContextDeep(breadcrumbItem);
510 
511         assertEquals(0, breadcrumbItem.getContext().size());
512         assertEquals(0, inputField.getContext().size());
513         assertEquals(0, fieldLabel.getContext().size());
514         assertEquals(0, labelTootlip.getContext().size());
515         assertEquals(0, tooltip.getContext().size());
516     }
517 
518     @Ignore // Ignored for now, this is a proof of concept for using reflection to test copying
519     @Test
520     /**
521      * test {@link ComponentUtils#copyUsingCloning} using a DataField object
522      */
523     public void testCopyUsingCloningWithDataTableSucceeds() {
524         CheckboxControl dataTableOriginal = new CheckboxControl();
525 
526         initializeClass(dataTableOriginal);
527 
528         CheckboxControl dataTableCopy = CopyUtils.copy(dataTableOriginal);
529 
530         assertTrue(propertiesMatch(dataTableOriginal, dataTableCopy));
531     }
532 
533     private void initializeClass(Object originalObject) {
534         Class originalClass = originalObject.getClass();
535         long index = 0L;
536 
537         for (Field field : originalClass.getDeclaredFields()) {
538             if (field.isAnnotationPresent(ReferenceCopy.class)) {
539                 continue;
540             }
541 
542             try {
543                 if (field.getType().equals(String.class)) {
544                     field.setAccessible(true);
545                     field.set(originalObject, "Test" + index);
546                 }
547 
548                 if (field.getType().equals(long.class)) {
549                     field.setAccessible(true);
550                     field.setLong(originalObject, index);
551                 }
552 
553                 if (field.getType().equals(int.class)) {
554                     field.setAccessible(true);
555                     field.setInt(originalObject, (int) index);
556                 }
557 
558                 if (field.getType().equals(List.class)) {
559                     field.setAccessible(true);
560                     ParameterizedType myListType = ((ParameterizedType) field.getGenericType());
561                     //myListType.getActualTypeArguments()[0].name;    // string value that looks like this: interface org.kuali.rice.krad.uif.component.Component
562                     int something = 2;
563                     //Class listClass = Class.forName(myListType.getActualTypeArguments()[0]);
564                     Object[] objects = new Object[1];
565                     objects[0] = new FieldBase();
566                     List<?> fieldList = Arrays.asList((Object[]) objects);
567                     field.set(originalObject, fieldList);
568                     List<?> retrievedList = (List<?>) field.get(originalObject);
569                     int somethingElse = 3;
570 
571                     //ArrayList<?> arrayList = new ArrayList<?>();
572 
573                 }
574             } catch (IllegalAccessException e) {
575                 // do nothing
576             }
577 
578             ++index;
579         }
580     }
581 
582     private boolean propertiesMatch(Object originalObject, Object copiedObject) {
583         Class originalClass = originalObject.getClass();
584         Class copiedClass = copiedObject.getClass();
585 
586         for (Field field : originalClass.getDeclaredFields()) {
587             if (field.isAnnotationPresent(ReferenceCopy.class)) {
588                 continue;
589             }
590 
591             if (field.getType().equals(String.class)) {
592                 boolean propertiesMatch = stringPropertiesMatch(originalObject, copiedObject, copiedClass, field);
593                 if (!propertiesMatch) {
594                     return false;
595                 }
596             }
597 
598             if (field.getType().equals(long.class)) {
599                 boolean propertiesMatch = longPropertiesMatch(originalObject, copiedObject, copiedClass, field);
600                 if (!propertiesMatch) {
601                     return false;
602                 }
603             }
604 
605             if (field.getType().equals(int.class)) {
606                 boolean propertiesMatch = intPropertiesMatch(originalObject, copiedObject, copiedClass, field);
607                 if (!propertiesMatch) {
608                     return false;
609                 }
610             }
611         }
612 
613         return true;
614     }
615 
616     private boolean intPropertiesMatch(Object originalObject, Object copiedObject, Class copiedClass, Field field) {
617         try {
618             field.setAccessible(true);
619             int oritinalInt = field.getInt(originalObject);
620             Field copiedClassField = copiedClass.getDeclaredField(field.getName());
621             copiedClassField.setAccessible(true);
622             int copiedInt = copiedClassField.getInt(copiedObject);
623 
624             return oritinalInt == copiedInt;
625         } catch (IllegalAccessException e) {
626             return false;
627         } catch (NoSuchFieldException e) {
628             return false;
629         }
630     }
631 
632     private boolean longPropertiesMatch(Object originalObject, Object copiedObject, Class copiedClass, Field field) {
633         try {
634             field.setAccessible(true);
635             Long originalLong = field.getLong(originalObject);
636             Field copiedClassField = copiedClass.getDeclaredField(field.getName());
637             copiedClassField.setAccessible(true);
638             Long copiedLong = copiedClassField.getLong(copiedObject);
639 
640             return originalLong.equals(copiedLong);
641         } catch (IllegalAccessException e) {
642             return false;
643         } catch (NoSuchFieldException e) {
644             return false;
645         }
646     }
647 
648     private boolean stringPropertiesMatch(Object originalObject, Object copiedObject, Class copiedClass, Field field) {
649         try {
650             field.setAccessible(true);
651             String originalString = (String) field.get(originalObject);
652             String copiedString = new String();
653             Field copiedClassField = copiedClass.getDeclaredField(field.getName());
654             copiedClassField.setAccessible(true);
655             copiedString = (String) copiedClassField.get(copiedObject);
656 
657             return originalString.equals(copiedString);
658         } catch (IllegalAccessException e) {
659             return false;
660         } catch (NoSuchFieldException e) {
661             return false;
662         }
663     }
664 }