@Test public void testMerge() throws Exception { MigrationDescriptor desc = (MigrationDescriptor) xmap.load( getResource("OSGI-INF/test-migration-descriptor.xml")); MigrationDescriptor desc2 = (MigrationDescriptor) xmap.load( getResource("OSGI-INF/test-migration-descriptor2.xml")); assertEquals(desc.id, desc2.id); desc = (MigrationDescriptor) desc.merge(desc2); assertEquals("my_migration", desc.id); assertEquals("newLabel", desc.descriptionLabel); assertEquals("New Descr", desc.description); assertEquals(java.lang.Boolean.class, desc.klass); assertEquals("v4", desc.defaultState); assertEquals(Arrays.asList("v1", "v2", "v3", "v4"), new ArrayList<>(desc.states.keySet())); MigrationStateDescriptor state; state = desc.states.get("v4"); assertEquals("v4", state.id); assertEquals("my_migration.state.v4", state.descriptionLabel); assertEquals("New State", state.description); assertEquals(Arrays.asList("first", "second", "third"), new ArrayList<>(desc.steps.keySet())); MigrationStepDescriptor step; step = desc.steps.get("third"); assertEquals("third", step.id); assertEquals("v3", step.fromState); assertEquals("v4", step.toState); assertEquals("my_migration.step.third", step.descriptionLabel); assertEquals("Third step of the migration, from v3 to v4", step.description); }
@Override public Descriptor merge(Descriptor o) { MigrationDescriptor other = (MigrationDescriptor) o; MigrationDescriptor merged = new MigrationDescriptor(); merged.id = id; merged.klass = other.klass != null ? other.klass : klass; merged.description = other.description != null ? other.description : description; merged.defaultState = other.defaultState != null ? other.defaultState : defaultState; merged.descriptionLabel = other.descriptionLabel != null ? other.descriptionLabel : descriptionLabel; merged.steps.putAll(steps); merged.steps.putAll(other.steps); merged.states.putAll(states); merged.states.putAll(other.states); return merged; }
MigrationDescriptor implements Descriptor { @Override public Descriptor merge(Descriptor o) { MigrationDescriptor other = (MigrationDescriptor) o; MigrationDescriptor merged = new MigrationDescriptor(); merged.id = id; merged.klass = other.klass != null ? other.klass : klass; merged.description = other.description != null ? other.description : description; merged.defaultState = other.defaultState != null ? other.defaultState : defaultState; merged.descriptionLabel = other.descriptionLabel != null ? other.descriptionLabel : descriptionLabel; merged.steps.putAll(steps); merged.steps.putAll(other.steps); merged.states.putAll(states); merged.states.putAll(other.states); return merged; } }
MigrationDescriptor implements Descriptor { @Override public Descriptor merge(Descriptor o) { MigrationDescriptor other = (MigrationDescriptor) o; MigrationDescriptor merged = new MigrationDescriptor(); merged.id = id; merged.klass = other.klass != null ? other.klass : klass; merged.description = other.description != null ? other.description : description; merged.defaultState = other.defaultState != null ? other.defaultState : defaultState; merged.descriptionLabel = other.descriptionLabel != null ? other.descriptionLabel : descriptionLabel; merged.steps.putAll(steps); merged.steps.putAll(other.steps); merged.states.putAll(states); merged.states.putAll(other.states); return merged; }  }
MigrationDescriptor implements Descriptor { @Override public Descriptor merge(Descriptor o) { MigrationDescriptor other = (MigrationDescriptor) o; MigrationDescriptor merged = new MigrationDescriptor(); merged.id = id; merged.klass = other.klass != null ? other.klass : klass; merged.description = other.description != null ? other.description : description; merged.defaultState = other.defaultState != null ? other.defaultState : defaultState; merged.descriptionLabel = other.descriptionLabel != null ? other.descriptionLabel : descriptionLabel; merged.steps.putAll(steps); merged.steps.putAll(other.steps); merged.states.putAll(states); merged.states.putAll(other.states); return merged; }  @Override String getId(); String getDescriptionLabel(); String getDescription(); Class<?> getKlass(); String getDefaultState(); Map<String, MigrationStateDescriptor> getStates(); Map<String, MigrationStepDescriptor> getSteps(); @Override Descriptor merge(Descriptor o); }
MigrationDescriptor implements Descriptor { @Override public Descriptor merge(Descriptor o) { MigrationDescriptor other = (MigrationDescriptor) o; MigrationDescriptor merged = new MigrationDescriptor(); merged.id = id; merged.klass = other.klass != null ? other.klass : klass; merged.description = other.description != null ? other.description : description; merged.defaultState = other.defaultState != null ? other.defaultState : defaultState; merged.descriptionLabel = other.descriptionLabel != null ? other.descriptionLabel : descriptionLabel; merged.steps.putAll(steps); merged.steps.putAll(other.steps); merged.states.putAll(states); merged.states.putAll(other.states); return merged; }  @Override String getId(); String getDescriptionLabel(); String getDescription(); Class<?> getKlass(); String getDefaultState(); Map<String, MigrationStateDescriptor> getStates(); Map<String, MigrationStepDescriptor> getSteps(); @Override Descriptor merge(Descriptor o); @XNode("@id")
    public String id; @XNode("description@label")
    public String descriptionLabel; @XNode("description")
    public String description; @XNode("class")
    public Class<?> klass; @XNode("defaultState")
    public String defaultState; @XNodeMap(value = "state", key = "@id", type = LinkedHashMap.class, componentType = MigrationStateDescriptor.class)
    public Map<String, MigrationStateDescriptor> states; @XNodeMap(value = "step", key = "@id", type = LinkedHashMap.class, componentType = MigrationStepDescriptor.class)
    public Map<String, MigrationStepDescriptor> steps; }