コード例 #1
0
  private void testUpdateCreate(boolean edit) throws ClassNotFoundException {
    final DateTime dtValue = DateUtil.now();

    mockSampleFields();
    mockDataService();
    mockEntity();
    when(motechDataService.retrieve("id", INSTANCE_ID)).thenReturn(new TestSample());

    List<FieldRecord> fieldRecords =
        asList(
            FieldTestHelper.fieldRecord("strField", String.class.getName(), "", "this is a test"),
            FieldTestHelper.fieldRecord("intField", Integer.class.getName(), "", 16),
            FieldTestHelper.fieldRecord("timeField", Time.class.getName(), "", "10:17"),
            FieldTestHelper.fieldRecord("dtField", DateTime.class.getName(), "", dtValue));

    Long id = (edit) ? INSTANCE_ID : null;
    EntityRecord record = new EntityRecord(id, ENTITY_ID, fieldRecords);

    MDSClassLoader.getInstance().loadClass(TestSample.class.getName());
    instanceService.saveInstance(record);

    ArgumentCaptor<TestSample> captor = ArgumentCaptor.forClass(TestSample.class);
    if (edit) {
      verify(motechDataService).update(captor.capture());
    } else {
      verify(motechDataService).create(captor.capture());
    }

    TestSample sample = captor.getValue();
    assertEquals("this is a test", sample.getStrField());
    assertEquals(Integer.valueOf(16), sample.getIntField());
    assertEquals(new Time(10, 17), sample.getTimeField());
    assertEquals(dtValue, sample.getDtField());
  }
コード例 #2
0
  private Class<?> getEntityClass(EntityDto entity) throws ClassNotFoundException {
    // get the declaring bundle, for DDE the module bundle, for EUDE the generated entities bundle
    Bundle declaringBundle;
    if (entity.isDDE()) {
      declaringBundle = MdsBundleHelper.searchForBundle(bundleContext, entity);
    } else {
      declaringBundle =
          WebBundleUtil.findBundleBySymbolicName(
              bundleContext, Constants.BundleNames.MDS_ENTITIES_SYMBOLIC_NAME);
    }

    Class<?> clazz;

    // if no bundle found, fallback to the MDSClassLoader
    if (declaringBundle == null) {
      clazz = MDSClassLoader.getInstance().loadClass(entity.getClassName());
    } else {
      clazz = declaringBundle.loadClass(entity.getClassName());
    }

    return clazz;
  }