@Test
  public void informationModel() throws Exception {
    String serviceUrl = "http://service.url";
    GridDataService dataService = new GridDataService();
    dataService.setUrl(serviceUrl);
    getGridServiceDao().save(dataService);
    Metadata meta = new Metadata();

    try {
      meta.dmodel =
          MetadataUtils.deserializeDomainModel(new FileReader("test/data/cabioModelSnippet.xml"));
      meta.smeta =
          MetadataUtils.deserializeServiceMetadata(
              new FileReader("test/data/cabioServiceMetadata.xml"));
    } catch (Exception ex) {
      fail("Error deserializing test data: " + ex.getMessage());
      ex.printStackTrace();
    }
    try {
      getMetadataListener().loadMetadata(dataService, meta);
    } catch (Exception ex) {
      fail("Error loading metadata: " + ex.getMessage());
      ex.printStackTrace();
    }

    ServiceMetadataCatalogEntryBuilder b =
        (ServiceMetadataCatalogEntryBuilder)
            getApplicationContext().getBean("serviceMetadataCatalogEntryBuilder");

    final GridServiceEndPointCatalogEntry endpointCe = b.build(dataService);
    assertTrue(endpointCe instanceof GridDataServiceEndPointCatalogEntry);

    InformationModelCatalogEntryDao infoDao =
        (InformationModelCatalogEntryDao)
            TestDB.getApplicationContext().getBean("informationModelCatalogEntryDao");

    assertEquals(1, infoDao.getAll().size());

    InformationModelCatalogEntry infoEntry = (InformationModelCatalogEntry) infoDao.getAll().get(0);
    infoEntry.setAuthor(pUser);
    infoDao.save(infoEntry);

    GridServiceEndPointCatalogEntry endpointCe2 = b.build(dataService);
    assertEquals(endpointCe.getId(), endpointCe2.getId());

    assertEquals("Duplicate Information Model CE is being created", 1, infoDao.getAll().size());
  }
Ejemplo n.º 2
0
  @Test
  public void metadataChange() {

    GridDataService dataService = new GridDataService();
    dataService.setUrl(
        "http://cabio-gridservice.nci.nih.gov:80/wsrf-cabio/services/cagrid/CaBIOSvc");
    getGridServiceDao().save(dataService);
    Metadata meta = new Metadata();
    try {
      meta.dmodel =
          MetadataUtils.deserializeDomainModel(new FileReader("test/data/cabioModelSnippet.xml"));
      meta.smeta =
          MetadataUtils.deserializeServiceMetadata(
              new FileReader("test/data/cabioServiceMetadata.xml"));
    } catch (Exception ex) {
      fail("Error deserializing test data: " + ex.getMessage());
      ex.printStackTrace();
    }
    try {
      getMetadataListener().loadMetadata(dataService, meta);
    } catch (Exception ex) {
      fail("Error loading metadata: " + ex.getMessage());
      ex.printStackTrace();
    }

    // Now associate some CQLQueryInstance and SharedCQLQuery objects
    String cql = null;
    try {
      cql = loadCQL("test/data/cabioMouseQuery.xml");
    } catch (Exception ex) {
      fail("Error loading test query: " + ex.getMessage());
      ex.printStackTrace();
    }

    CQLQuery query = new CQLQuery();
    query.setXml(cql);
    query.setHash(PortalUtils.createHash(cql));
    getCqlQueryDao().save(query);
    CQLQueryInstance instance = new CQLQueryInstance();
    instance.setQuery(query);
    instance.setDataService(dataService);
    getCqlQueryInstanceDao().save(instance);

    String targetClassName = "gov.nih.nci.cabio.domain.Gene";
    UMLClass targetClass = null;
    for (UMLClass klass : dataService.getDomainModel().getClasses()) {
      String className = klass.getPackageName() + "." + klass.getClassName();
      if (className.equals(targetClassName)) {
        targetClass = klass;
        break;
      }
    }
    SharedCQLQuery sharedCqlQuery = new SharedCQLQuery();
    sharedCqlQuery.setTargetClass(targetClass);
    sharedCqlQuery.setTargetService(dataService);
    getSharedCqlQueryDao().save(sharedCqlQuery);

    verify(dataService, getSharedCqlQueryDao(), getCqlQueryInstanceDao(), targetClassName);

    try {
      getChangeListener().updateServiceMetadata(dataService.getUrl(), meta);
    } catch (Exception ex) {
      fail("Error updating metadata: " + ex.getMessage());
      ex.printStackTrace();
    }

    verify(dataService, getSharedCqlQueryDao(), getCqlQueryInstanceDao(), targetClassName);
  }