// Path: modules/common/test/edu/berkeley/ground/common/util/ModelTestUtils.java
// public static String convertFromClassToString(Object object) {
//   return Json.stringify(Json.toJson(object));
// }
// 
// Path: modules/common/test/edu/berkeley/ground/common/util/ModelTestUtils.java
// public static Object convertFromStringToClass(String body, Class<?> klass) {
//   return Json.fromJson(Json.parse(body), klass);
// }
// 
// Path: modules/common/test/edu/berkeley/ground/common/util/ModelTestUtils.java
// public static String readFromFile(String filename) throws GroundException {
//   try {
//     String content = new Scanner(new File(filename)).useDelimiter("\\Z").next();
// 
//     return content;
//   } catch (FileNotFoundException e) {
//     throw new GroundException(ExceptionType.OTHER, String.format("File %s not found", filename));
//   }
// }
// 
// Path: modules/common/app/edu/berkeley/ground/common/model/version/GroundType.java
// public enum GroundType {
//   STRING(String.class, "string", Types.VARCHAR) {
//     @Override
//     public Object parse(String str) {
//       return str;
//     }
//   },
//   INTEGER(Integer.class, "integer", Types.INTEGER) {
//     @Override
//     public Object parse(String str) {
//       return Integer.parseInt(str);
//     }
//   },
//   BOOLEAN(Boolean.class, "boolean", Types.BOOLEAN) {
//     @Override
//     public Object parse(String str) {
//       return Boolean.parseBoolean(str);
//     }
//   },
//   LONG(Long.class, "long", Types.BIGINT) {
//     @Override
//     public Object parse(String str) {
//       return Long.parseLong(str);
//     }
//   };
// 
//   private final Class<?> klass;
//   private final String name;
//   private final int sqlType;
// 
//   GroundType(Class<?> klass, String name, int sqlType) {
//     this.klass = klass;
//     this.name = name;
//     this.sqlType = sqlType;
//   }
// 
//   /**
//    * Returns the SQL type as defined in java.sql.Types corresponding to this GroundType
//    *
//    * @return an integer the corresponding SQL Type
//    */
//   public int getSqlType() {
//     return sqlType;
//   }
// 
//   public abstract Object parse(String str);
// 
//   public Class<?> getTypeClass() {
//     return this.klass;
//   }
// 
//   /**
//    * Return a type based on the string name.
//    *
//    * @param str the name of the type
//    * @return the corresponding GroundType
//    * @throws GroundException no such type
//    */
//   @JsonCreator
//   public static GroundType fromString(String str) throws GroundException {
//     if (str == null) {
//       return null;
//     }
//     try {
//       return GroundType.valueOf(str.toUpperCase());
//     } catch (IllegalArgumentException iae) {
//       throw new GroundException(ExceptionType.OTHER, String.format("Invalid type: %s.", str));
//     }
//   }
// 
//   @Override
//   public String toString() {
//     return this.name;
//   }
// }


import static edu.berkeley.ground.common.util.ModelTestUtils.convertFromClassToString;
import static edu.berkeley.ground.common.util.ModelTestUtils.convertFromStringToClass;
import static edu.berkeley.ground.common.util.ModelTestUtils.readFromFile;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import edu.berkeley.ground.common.model.version.GroundType;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
/**
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package edu.berkeley.ground.common.model.core;



public class StructureVersionTest {

  @Test
  public void serializesToJSON() throws Exception {
    Map<String, GroundType> attributes = new HashMap<>();
    attributes.put("tag1", GroundType.INTEGER);
    attributes.put("tag2", GroundType.STRING);

    StructureVersion structureVersion = new StructureVersion(1, 1, attributes);

    final String expected = convertFromClassToString(convertFromStringToClass(readFromFile
      ("test/resources/fixtures/core/structure_version.json"), StructureVersion.class));
    assertEquals(convertFromClassToString(structureVersion), expected);
  }

  @Test
  public void deserializesFromJSON() throws Exception {
    Map<String, GroundType> attributes = new HashMap<>();
    attributes.put("tag1", GroundType.INTEGER);
    attributes.put("tag2", GroundType.STRING);

    StructureVersion structureVersion = new StructureVersion(1, 1, attributes);

    assertEquals(convertFromStringToClass(
      readFromFile("test/resources/fixtures/core/structure_version.json"),
      StructureVersion.class), structureVersion);
  }

  @Test
  public void testStructureVersionNotEquals() throws Exception {
    StructureVersion truth = new StructureVersion(1, 2, new HashMap<>());
    assertFalse(truth.equals("notStructureVersion"));

    StructureVersion differentId = new StructureVersion(10, 2, new HashMap<>());
    assertFalse(truth.equals(differentId));

    StructureVersion differentStructureId = new StructureVersion(1, 10, new HashMap<>());
// Path: modules/common/test/edu/berkeley/ground/common/util/ModelTestUtils.java
// public static String convertFromClassToString(Object object) {
//   return Json.stringify(Json.toJson(object));
// }
// 
// Path: modules/common/test/edu/berkeley/ground/common/util/ModelTestUtils.java
// public static Object convertFromStringToClass(String body, Class<?> klass) {
//   return Json.fromJson(Json.parse(body), klass);
// }
// 
// Path: modules/common/test/edu/berkeley/ground/common/util/ModelTestUtils.java
// public static String readFromFile(String filename) throws GroundException {
//   try {
//     String content = new Scanner(new File(filename)).useDelimiter("\\Z").next();
// 
//     return content;
//   } catch (FileNotFoundException e) {
//     throw new GroundException(ExceptionType.OTHER, String.format("File %s not found", filename));
//   }
// }
// 
// Path: modules/common/app/edu/berkeley/ground/common/model/version/GroundType.java
// public enum GroundType {
//   STRING(String.class, "string", Types.VARCHAR) {
//     @Override
//     public Object parse(String str) {
//       return str;
//     }
//   },
//   INTEGER(Integer.class, "integer", Types.INTEGER) {
//     @Override
//     public Object parse(String str) {
//       return Integer.parseInt(str);
//     }
//   },
//   BOOLEAN(Boolean.class, "boolean", Types.BOOLEAN) {
//     @Override
//     public Object parse(String str) {
//       return Boolean.parseBoolean(str);
//     }
//   },
//   LONG(Long.class, "long", Types.BIGINT) {
//     @Override
//     public Object parse(String str) {
//       return Long.parseLong(str);
//     }
//   };
// 
//   private final Class<?> klass;
//   private final String name;
//   private final int sqlType;
// 
//   GroundType(Class<?> klass, String name, int sqlType) {
//     this.klass = klass;
//     this.name = name;
//     this.sqlType = sqlType;
//   }
// 
//   /**
//    * Returns the SQL type as defined in java.sql.Types corresponding to this GroundType
//    *
//    * @return an integer the corresponding SQL Type
//    */
//   public int getSqlType() {
//     return sqlType;
//   }
// 
//   public abstract Object parse(String str);
// 
//   public Class<?> getTypeClass() {
//     return this.klass;
//   }
// 
//   /**
//    * Return a type based on the string name.
//    *
//    * @param str the name of the type
//    * @return the corresponding GroundType
//    * @throws GroundException no such type
//    */
//   @JsonCreator
//   public static GroundType fromString(String str) throws GroundException {
//     if (str == null) {
//       return null;
//     }
//     try {
//       return GroundType.valueOf(str.toUpperCase());
//     } catch (IllegalArgumentException iae) {
//       throw new GroundException(ExceptionType.OTHER, String.format("Invalid type: %s.", str));
//     }
//   }
// 
//   @Override
//   public String toString() {
//     return this.name;
//   }
// }


// Path: modules/common/test/edu/berkeley/ground/common/model/core/StructureVersionTest.java
import static edu.berkeley.ground.common.util.ModelTestUtils.convertFromClassToString;
import static edu.berkeley.ground.common.util.ModelTestUtils.convertFromStringToClass;
import static edu.berkeley.ground.common.util.ModelTestUtils.readFromFile;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import edu.berkeley.ground.common.model.version.GroundType;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;

/**
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package edu.berkeley.ground.common.model.core;



public class StructureVersionTest {

  @Test
  public void serializesToJSON() throws Exception {
    Map<String, GroundType> attributes = new HashMap<>();
    attributes.put("tag1", GroundType.INTEGER);
    attributes.put("tag2", GroundType.STRING);

    StructureVersion structureVersion = new StructureVersion(1, 1, attributes);

    final String expected = convertFromClassToString(convertFromStringToClass(readFromFile
      ("test/resources/fixtures/core/structure_version.json"), StructureVersion.class));
    assertEquals(convertFromClassToString(structureVersion), expected);
  }

  @Test
  public void deserializesFromJSON() throws Exception {
    Map<String, GroundType> attributes = new HashMap<>();
    attributes.put("tag1", GroundType.INTEGER);
    attributes.put("tag2", GroundType.STRING);

    StructureVersion structureVersion = new StructureVersion(1, 1, attributes);

    assertEquals(convertFromStringToClass(
      readFromFile("test/resources/fixtures/core/structure_version.json"),
      StructureVersion.class), structureVersion);
  }

  @Test
  public void testStructureVersionNotEquals() throws Exception {
    StructureVersion truth = new StructureVersion(1, 2, new HashMap<>());
    assertFalse(truth.equals("notStructureVersion"));

    StructureVersion differentId = new StructureVersion(10, 2, new HashMap<>());
    assertFalse(truth.equals(differentId));

    StructureVersion differentStructureId = new StructureVersion(1, 10, new HashMap<>());
    assertFalse(truth.equals(differentStructureId));