/*
 * Copyright (C) 2013 The enviroCar project
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.envirocar.server.rest.schema;

import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;

import java.util.Scanner;

import org.envirocar.server.rest.MediaTypes;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
 * TODO JavaDoc
 *
 */
@RunWith(GuiceRunner.class)
public class MeasurementsValidationTest {

	@Rule
	public final ValidationRule validate = new ValidationRule();

	@Test
	public void validateValidTrackInstance() {
		assertThat(validate.parse(loadTrackInstance("measurements-instance.json")),
				is(validate.validInstanceOf(MediaTypes.MEASUREMENTS_TYPE)));
	}
	
	@Test
	public void validateValidTrackInstanceWithoutTrackReference() {
		assertThat(validate.parse(loadTrackInstance("measurements-instance-wo-trackref.json")),
				is(validate.validInstanceOf(MediaTypes.MEASUREMENTS_TYPE)));
	}

	private String loadTrackInstance(String res) {
		StringBuilder sb = new StringBuilder();
		
		Scanner sc = null;
		sc = new Scanner(getClass().getResourceAsStream(res));
		while (sc.hasNext()) {
			sb.append(sc.nextLine());
		}
		sc.close();
		
		return sb.toString();
	}
}

@@ -1186,37 +1186,44 @@
 id validateValid
-Track
+Measurements
 Instance() %7B%0A%09%09a
@@ -1243,37 +1243,44 @@
 idate.parse(load
-Track
+Measurements
 Instance(%22measur
@@ -1407,21 +1407,28 @@
 ateValid
-Track
+Measurements
 Instance
@@ -1481,29 +1481,36 @@
 e.parse(load
-Track
+Measurements
 Instance(%22me
@@ -1639,21 +1639,28 @@
 ing load
-Track
+Measurements
 Instance

fix c&p name issues