001/*
002 * ModeShape (http://www.modeshape.org)
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *       http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.modeshape.schematic.internal.document;
017
018import static org.hamcrest.core.Is.is;
019import static org.junit.Assert.assertThat;
020import java.io.InputStream;
021import org.junit.Test;
022import org.modeshape.schematic.document.Document;
023import org.modeshape.schematic.document.EditableDocument;
024import org.modeshape.schematic.document.Json;
025
026public class DocumentEditorTest {
027
028    protected InputStream stream( String path ) {
029        return this.getClass().getClassLoader().getResourceAsStream(path);
030    }
031
032    @Test
033    public void shouldMergeTwoDocuments() throws Exception {
034        Document doc1 = Json.read(stream("json/merge-1.json"));
035        Document doc2 = Json.read(stream("json/merge-2.json"));
036        Document doc3 = Json.read(stream("json/merge-3.json"));
037        EditableDocument editor = new DocumentEditor((MutableDocument)doc1);
038        assertThat(Json.writePretty(editor).equals(Json.writePretty(doc3)), is(false));
039        editor.merge(doc2);
040        assertThat(Json.writePretty(editor).equals(Json.writePretty(doc3)), is(true));
041    }
042}