SampleWrapper implements BioMoleculeWrapperI { @Override public List<SampleMeta> updateMetaToList(List<SampleMeta> inputMetaList, SampleMetaDao sampleMetaDao){ return updateMetaToList(inputMetaList, sampleMetaDao, true); } SampleWrapper(Sample sample); @Override List<SampleMeta> getAllSampleMeta(); @Override Sample getSampleObject(); @Override SampleWrapper getParentWrapper(); @Override Set<String> getAllSampleMetaAreas(); @Override List<SampleMeta> getMetaTemplatedToSampleSybtype(SampleSubtype sampleSubtype); @Override void setParent(Sample parentSample); @Override List<SampleMeta> updateMetaToList(List<SampleMeta> inputMetaList, SampleMetaDao sampleMetaDao); @Override void saveAll(SampleService sampleService);  }
@Test (groups = "unit-tests", dependsOnMethods = {"testSampleWrapperConstruct"}) public void testUpdateMetaToList1(){ SampleWrapper managedSample = new SampleWrapper(sample); List<SampleMeta> inputMetaList = new ArrayList<SampleMeta>(); SampleMeta sm1 = new SampleMeta(); sm1.setSampleId(1); sm1.setK("sampleMeta1.key1"); sm1.setV("1"); inputMetaList.add(sm1); SampleMeta sm2 = new SampleMeta(); sm2.setSampleId(2); sm2.setK("parentSampleMeta2.key3"); sm2.setV("10"); inputMetaList.add(sm2); SampleMeta sm3 = new SampleMeta(); sm3.setK("sampleMeta1.key2"); sm3.setV("2"); inputMetaList.add(sm3); SampleMeta sm5 = new SampleMeta(); sm5.setK("parentSampleMeta2.key5"); sm5.setV("11"); inputMetaList.add(sm5); SampleMeta sm6 = new SampleMeta(); sm6.setSampleId(2); sm6.setK("anotherarea.key1"); sm6.setV("12"); inputMetaList.add(sm6); SampleMeta sm7 = new SampleMeta(); sm7.setK("anotherarea.key2"); sm7.setV("13"); inputMetaList.add(sm7); SampleMeta sm8 = new SampleMeta(); sm8.setSampleId(3); sm8.setK("sampleMeta3.key1"); sm8.setV("14"); inputMetaList.add(sm8); SampleMetaDao mockSampleMetaDao = createMockBuilder(SampleMetaDaoImpl.class).addMockedMethods(SampleMetaDaoImpl.class.getMethods()).createMock(); Assert.assertNotNull(mockSampleMetaDao); expect(mockSampleMetaDao.save(sampleMeta2)).andReturn(sampleMeta2); expect(mockSampleMetaDao.save(sampleMeta4)).andReturn(sampleMeta4); expect(mockSampleMetaDao.save(sm2)).andReturn(sm2); expect(mockSampleMetaDao.save(sm6)).andReturn(sm6); expect(mockSampleMetaDao.save(sm5)).andReturn(sm5); expect(mockSampleMetaDao.save(sm7)).andReturn(sm7); replay(mockSampleMetaDao); List<SampleMeta> newSampleMetaList = managedSample.updateMetaToList(inputMetaList, mockSampleMetaDao); Map<String, SampleMeta> results = new HashMap<String, SampleMeta>(); for (SampleMeta m: newSampleMetaList){ logger.debug(m.toString()+": sampleId: "+m.getSampleId()); results.put(m.getK(), m); } Assert.assertEquals(newSampleMetaList.size(), 7); Assert.assertEquals(results.get("sampleMeta1.key1").getV(), "1"); Assert.assertEquals(results.get("parentSampleMeta2.key3").getV(), "10"); Assert.assertEquals(results.get("parentSampleMeta2.key3").getSampleId().intValue(), 2); Assert.assertEquals(results.get("sampleMeta1.key2").getV(), "2"); Assert.assertEquals(results.get("sampleMeta1.key2").getSampleId().intValue(), 1); Assert.assertTrue(results.containsKey("parentSampleMeta2.key5")); Assert.assertEquals(results.get("parentSampleMeta2.key5").getV(), "11"); Assert.assertEquals(results.get("parentSampleMeta2.key5").getSampleId().intValue(), 1); Assert.assertTrue(results.containsKey("anotherarea.key1")); Assert.assertEquals(results.get("anotherarea.key1").getV(), "12"); Assert.assertEquals(results.get("anotherarea.key1").getSampleId().intValue(), 2); Assert.assertTrue(results.containsKey("anotherarea.key2")); Assert.assertEquals(results.get("anotherarea.key2").getV(), "13"); Assert.assertEquals(results.get("anotherarea.key2").getSampleId().intValue(), 1); Assert.assertFalse(results.containsKey("sampleMeta3.key1")); verify(mockSampleMetaDao); }
@Test (groups = "unit-tests", dependsOnMethods = {"testSampleWrapperConstruct"}) public void testUpdateMetaToList2(){ SampleWrapper managedSample = new SampleWrapper(sample); sample.setSampleId(null); List<SampleMeta> inputMetaList = new ArrayList<SampleMeta>(); SampleMeta sm1 = new SampleMeta(); sm1.setK("sampleMeta1.key1"); sm1.setV("1"); inputMetaList.add(sm1); SampleMeta sm2 = new SampleMeta(); sm2.setK("anotherarea.key1"); sm2.setV("12"); inputMetaList.add(sm2); SampleMeta sm3 = new SampleMeta(); sm3.setSampleId(3); sm3.setK("sampleMeta3.key1"); sm3.setV("14"); inputMetaList.add(sm3); SampleMeta sm4 = new SampleMeta(); sm4.setK("parentSampleMeta2.key3"); sm4.setSampleId(2); sm4.setV("10"); inputMetaList.add(sm4); SampleMetaDao mockSampleMetaDao = createMockBuilder(SampleMetaDaoImpl.class).addMockedMethods(SampleMetaDaoImpl.class.getMethods()).createMock(); Assert.assertNotNull(mockSampleMetaDao); expect(mockSampleMetaDao.save(sm4)).andReturn(sm4); expect(mockSampleMetaDao.save(sampleMeta4)).andReturn(sampleMeta4); replay(mockSampleMetaDao); List<SampleMeta> newSampleMetaList = managedSample.updateMetaToList(inputMetaList, mockSampleMetaDao); Map<String, SampleMeta> results = new HashMap<String, SampleMeta>(); for (SampleMeta m: newSampleMetaList){ logger.debug(m.toString()+": sampleId: "+m.getSampleId()); results.put(m.getK(), m); } Assert.assertEquals(results.get("sampleMeta1.key1").getV(), "1"); Assert.assertEquals(results.get("anotherarea.key1").getV(), "12"); Assert.assertNull(results.get("anotherarea.key1").getSampleId()); Assert.assertEquals(results.get("parentSampleMeta2.key3").getV(), "10"); Assert.assertEquals(results.get("parentSampleMeta2.key3").getSampleId().intValue(), 2); Assert.assertFalse(results.containsKey("sampleMeta3.key1")); verify(mockSampleMetaDao); }