/*
 * This file is part of Sponge, licensed under the MIT License (MIT).
 *
 * Copyright (c) SpongePowered <https://www.spongepowered.org>
 * Copyright (c) contributors
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package org.spongepowered.common.regression;

import static org.junit.Assert.assertEquals;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.spongepowered.api.data.DataContainer;
import org.spongepowered.api.data.persistence.DataFormats;
import org.spongepowered.api.data.persistence.DataTranslators;
import org.spongepowered.api.world.schematic.Schematic;
import org.spongepowered.lwts.runner.LaunchWrapperTestRunner;

import java.io.IOException;
import java.io.InputStream;
import java.util.zip.GZIPInputStream;

@RunWith(LaunchWrapperTestRunner.class)
public class SchematicUpgradeTest {

    @Test
    public void testUpgradingv1Tov2() throws IOException {
        InputStream inputStream = this.getClass().getClassLoader().getResource("loadv1.schematic").openStream();
        DataContainer container = DataFormats.NBT.readFrom(new GZIPInputStream(inputStream));
        final Schematic v1Schem = DataTranslators.SCHEMATIC.translate(container);
        inputStream = this.getClass().getClassLoader().getResource("loadv2.schematic").openStream();
        container = DataFormats.NBT.readFrom(new GZIPInputStream(inputStream));
        final Schematic v2Schem = DataTranslators.SCHEMATIC.translate(container);
        assertEquals(v1Schem, v2Schem);
    }

}

@@ -1928,16 +1928,95 @@
         
+ClassLoader classLoader = this.getClass().getClassLoader();%0A        try (final 
 InputStr
@@ -2019,17 +2019,19 @@
 tStream 
-i
+v1I
 nputStre
@@ -2035,36 +2035,122 @@
 tream = 
-this.getClass().getC
+classLoader.getResource(%22loadv1.schematic%22).openStream();%0A             final InputStream v2InputStream = c
 lassLoad
@@ -2143,34 +2143,32 @@
 am = classLoader
-()
 .getResource(%22lo
@@ -2162,33 +2162,33 @@
 tResource(%22loadv
-1
+2
 .schematic%22).ope
@@ -2196,26 +2196,30 @@
 Stream()
-;%0A
+) %7B%0A  
         
 DataCont
@@ -2210,16 +2210,28 @@
         
+      final 
 DataCont
@@ -2236,17 +2236,19 @@
 ntainer 
-c
+v1C
 ontainer
@@ -2287,33 +2287,35 @@
 GZIPInputStream(
-i
+v1I
 nputStream));%0A  
@@ -2312,32 +2312,40 @@
 ream));%0A        
+   
+     
 final Schematic 
@@ -2382,33 +2382,35 @@
 MATIC.translate(
-c
+v1C
 ontainer);%0A     
@@ -2416,110 +2416,39 @@
     
-inputStream = this.getClass().getClassLoader().getResource(%22loadv2.schematic%22).openStream();%0A        c
+        final DataContainer v2C
 onta
@@ -2499,17 +2499,19 @@
 tStream(
-i
+v2I
 nputStre
@@ -2508,32 +2508,40 @@
 2InputStream));%0A
+        
         final Sc
@@ -2594,17 +2594,19 @@
 anslate(
-c
+v2C
 ontainer
@@ -2600,32 +2600,40 @@
 e(v2Container);%0A
+        
         assertEq
@@ -2656,16 +2656,26 @@
 Schem);%0A
+        %7D%0A
     %7D%0A%0A%7D

Update SchematicUpgradeTest.java