Search in sources :

Example 1 with SoapApiCommand

use of com.zimbra.doc.soap.apidesc.SoapApiCommand in project zm-mailbox by Zimbra.

the class SoapApiChangeLog method makeChangeLogDataModel.

public void makeChangeLogDataModel() throws JsonParseException, JsonMappingException, IOException, TemplateException {
    Map<String, SoapApiCommand> baselineCmds = Maps.newTreeMap();
    Map<String, SoapApiCommand> currentCmds = Maps.newTreeMap();
    for (SoapApiCommand cmd : currentDesc.getCommands()) {
        currentCmds.put(cmd.getId(), cmd);
    }
    for (SoapApiCommand cmd : baselineDesc.getCommands()) {
        baselineCmds.put(cmd.getId(), cmd);
    }
    for (Entry<String, SoapApiCommand> entry : currentCmds.entrySet()) {
        SoapApiCommand baselineCmd = baselineCmds.get(entry.getKey());
        if (baselineCmd != null) {
            CommandChanges cmd = new CommandChanges(baselineCmd, entry.getValue(), baselineDesc.getTypes(), currentDesc.getTypes());
            if (cmd.hasChanges()) {
                modifiedCommands.add(cmd);
            }
        } else {
            newCommands.add(entry.getValue());
        }
    }
    for (Entry<String, SoapApiCommand> entry : baselineCmds.entrySet()) {
        if (!currentCmds.containsKey(entry.getKey())) {
            deletedCommands.add(entry.getValue());
        }
    }
    changelogDataModel = createChangeLogDataModel();
}
Also used : SoapApiCommand(com.zimbra.doc.soap.apidesc.SoapApiCommand)

Example 2 with SoapApiCommand

use of com.zimbra.doc.soap.apidesc.SoapApiCommand in project zm-mailbox by Zimbra.

the class ChangelogTest method makeChangelogTest.

@Test
public void makeChangelogTest() throws Exception {
    Map<String, ApiClassDocumentation> javadocInfo = Maps.newTreeMap();
    List<Class<?>> classes = Lists.newArrayList();
    classes.add(aRequest.class);
    classes.add(aResponse.class);
    classes.add(bRequest.class);
    classes.add(bResponse.class);
    classes.add(cRequest.class);
    classes.add(cResponse.class);
    Root soapApiDataModelRoot = WsdlDocGenerator.processJaxbClasses(javadocInfo, classes);
    SoapApiDescription jsonDescCurrent = new SoapApiDescription("7.99.99", "20000131-2359");
    jsonDescCurrent.build(soapApiDataModelRoot);
    // File json = new File("/tmp/test1.json");
    // jsonDescCurrent.serializeToJson(json);
    InputStream is = getClass().getResourceAsStream("baseline1.json");
    SoapApiDescription jsonDescBaseline = SoapApiDescription.deserializeFromJson(is);
    SoapApiChangeLog clog = new SoapApiChangeLog();
    clog.setBaselineDesc(jsonDescBaseline);
    clog.setCurrentDesc(jsonDescCurrent);
    clog.makeChangeLogDataModel();
    List<SoapApiCommand> newCmds = clog.getNewCommands();
    LOG.info("    New Command:" + newCmds.get(0).getName());
    List<SoapApiCommand> delCmds = clog.getDeletedCommands();
    LOG.info("    Deleted Command:" + delCmds.get(0).getName());
    List<CommandChanges> modCmds = clog.getModifiedCommands();
    CommandChanges modCmd = modCmds.get(0);
    LOG.info("    Modified Command:" + modCmd.getName());
    List<NamedAttr> delAttrs = modCmd.getDeletedAttrs();
    for (NamedAttr attr : delAttrs) {
        LOG.info("    Deleted Attribute:" + attr.getXpath());
    }
    List<NamedAttr> addAttrs = modCmd.getNewAttrs();
    for (NamedAttr attr : addAttrs) {
        LOG.info("    Added Attribute:" + attr.getXpath());
    }
    List<AttributeChanges> modAttrs = modCmd.getModifiedAttrs();
    for (AttributeChanges modAttr : modAttrs) {
        LOG.info("    Modified Attribute " + modAttr.getXpath() + ":\nbase=" + modAttr.getBaselineRepresentation() + "\ncurr=" + modAttr.getCurrentRepresentation());
    }
    List<NamedElem> delEs = modCmd.getDeletedElems();
    for (NamedElem el : delEs) {
        LOG.info("    Deleted Element :" + el.getXpath());
    }
    List<NamedElem> newEs = modCmd.getNewElems();
    for (NamedElem el : newEs) {
        LOG.info("    New Element :" + el.getXpath());
    }
    List<ElementChanges> modEs = modCmd.getModifiedElements();
    for (ElementChanges el : modEs) {
        LOG.info("    Modified Element " + el.getXpath() + ":\nbase=" + el.getBaselineRepresentation() + "\ncurr=" + el.getCurrentRepresentation());
    }
    Assert.assertEquals("Number of new commands", 1, newCmds.size());
    Assert.assertEquals("Number of deleted commands", 1, delCmds.size());
    Assert.assertEquals("Number of modified commands", 1, modCmds.size());
    Assert.assertEquals("Number of deleted attributes", 1, delAttrs.size());
    Assert.assertEquals("Number of new attributes", 1, addAttrs.size());
    Assert.assertEquals("Number of modified attributes", 1, modAttrs.size());
    Assert.assertEquals("Number of deleted elements", 1, delEs.size());
    Assert.assertEquals("Number of new elements", 1, newEs.size());
    Assert.assertEquals("Number of modified elements", 1, modEs.size());
}
Also used : AttributeChanges(com.zimbra.doc.soap.changelog.AttributeChanges) InputStream(java.io.InputStream) NamedElem(com.zimbra.doc.soap.changelog.CommandChanges.NamedElem) SoapApiChangeLog(com.zimbra.doc.soap.changelog.SoapApiChangeLog) NamedAttr(com.zimbra.doc.soap.changelog.CommandChanges.NamedAttr) CommandChanges(com.zimbra.doc.soap.changelog.CommandChanges) ElementChanges(com.zimbra.doc.soap.changelog.ElementChanges) BeforeClass(org.junit.BeforeClass) SoapApiCommand(com.zimbra.doc.soap.apidesc.SoapApiCommand) SoapApiDescription(com.zimbra.doc.soap.apidesc.SoapApiDescription) Test(org.junit.Test)

Aggregations

SoapApiCommand (com.zimbra.doc.soap.apidesc.SoapApiCommand)2 SoapApiDescription (com.zimbra.doc.soap.apidesc.SoapApiDescription)1 AttributeChanges (com.zimbra.doc.soap.changelog.AttributeChanges)1 CommandChanges (com.zimbra.doc.soap.changelog.CommandChanges)1 NamedAttr (com.zimbra.doc.soap.changelog.CommandChanges.NamedAttr)1 NamedElem (com.zimbra.doc.soap.changelog.CommandChanges.NamedElem)1 ElementChanges (com.zimbra.doc.soap.changelog.ElementChanges)1 SoapApiChangeLog (com.zimbra.doc.soap.changelog.SoapApiChangeLog)1 InputStream (java.io.InputStream)1 BeforeClass (org.junit.BeforeClass)1 Test (org.junit.Test)1