// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.controller.api.integration.deployment;

import com.yahoo.config.provision.Environment;
import com.yahoo.config.provision.SystemName;
import com.yahoo.config.provision.zone.ZoneId;
import com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneRegistry;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

/**
 * @author jonmv
 */
public class JobTypeTest {

    @Test
    public void test() {
        for (JobType type : JobType.values()) {
            if (type.isProduction()) {
                boolean match = false;
                for (JobType other : JobType.values())
                    match |=    type != other
                             && type.isTest() == other.isDeployment()
                             && type.zones.equals(other.zones);

                assertTrue(type + " should have matching job", match);
            }
        }

        assertEquals(JobType.testUsEast3, JobType.fromJobName("prod.us-east-3.test"));
        assertEquals(JobType.devAwsUsEast1c, JobType.fromJobName("dev.aws-us-east-1c"));

        assertFalse(JobType.dev("snøhetta").isTest());
        assertTrue(JobType.dev("snøhetta").isDeployment());
        assertFalse(JobType.dev("snøhetta").isProduction());

        assertFalse(JobType.perf("snøhetta").isTest());
        assertTrue(JobType.perf("snøhetta").isDeployment());
        assertFalse(JobType.perf("snøhetta").isProduction());

        assertTrue(JobType.deploymentTo(ZoneId.from("test", "snøhetta")).isTest());
        assertTrue(JobType.deploymentTo(ZoneId.from("test", "snøhetta")).isDeployment());
        assertFalse(JobType.deploymentTo(ZoneId.from("test", "snøhetta")).isProduction());

        assertTrue(JobType.deploymentTo(ZoneId.from("staging", "snøhetta")).isTest());
        assertTrue(JobType.deploymentTo(ZoneId.from("staging", "snøhetta")).isDeployment());
        assertFalse(JobType.deploymentTo(ZoneId.from("staging", "snøhetta")).isProduction());

        assertFalse(JobType.prod("snøhetta").isTest());
        assertTrue(JobType.prod("snøhetta").isDeployment());
        assertTrue(JobType.prod("snøhetta").isProduction());

        assertTrue(JobType.test("snøhetta").isTest());
        assertFalse(JobType.test("snøhetta").isDeployment());
        assertTrue(JobType.test("snøhetta").isProduction());
    }

}

@@ -1292,33 +1292,33 @@
 (JobType.dev(%22sn
-%C3%B8
+o
 hetta%22).isTest()
@@ -1346,33 +1346,33 @@
 (JobType.dev(%22sn
-%C3%B8
+o
 hetta%22).isDeploy
@@ -1411,25 +1411,25 @@
 Type.dev(%22sn
-%C3%B8
+o
 hetta%22).isPr
@@ -1470,33 +1470,33 @@
 JobType.perf(%22sn
-%C3%B8
+o
 hetta%22).isTest()
@@ -1525,33 +1525,33 @@
 JobType.perf(%22sn
-%C3%B8
+o
 hetta%22).isDeploy
@@ -1591,25 +1591,25 @@
 ype.perf(%22sn
-%C3%B8
+o
 hetta%22).isPr
@@ -1677,33 +1677,33 @@
 from(%22test%22, %22sn
-%C3%B8
+o
 hetta%22)).isTest(
@@ -1761,33 +1761,33 @@
 from(%22test%22, %22sn
-%C3%B8
+o
 hetta%22)).isDeplo
@@ -1856,25 +1856,25 @@
 (%22test%22, %22sn
-%C3%B8
+o
 hetta%22)).isP
@@ -1946,33 +1946,33 @@
 m(%22staging%22, %22sn
-%C3%B8
+o
 hetta%22)).isTest(
@@ -2033,33 +2033,33 @@
 m(%22staging%22, %22sn
-%C3%B8
+o
 hetta%22)).isDeplo
@@ -2135,17 +2135,17 @@
 ng%22, %22sn
-%C3%B8
+o
 hetta%22))
@@ -2191,33 +2191,33 @@
 JobType.prod(%22sn
-%C3%B8
+o
 hetta%22).isTest()
@@ -2246,33 +2246,33 @@
 JobType.prod(%22sn
-%C3%B8
+o
 hetta%22).isDeploy
@@ -2311,25 +2311,25 @@
 ype.prod(%22sn
-%C3%B8
+o
 hetta%22).isPr
@@ -2369,33 +2369,33 @@
 JobType.test(%22sn
-%C3%B8
+o
 hetta%22).isTest()
@@ -2425,33 +2425,33 @@
 JobType.test(%22sn
-%C3%B8
+o
 hetta%22).isDeploy
@@ -2498,9 +2498,9 @@
 (%22sn
-%C3%B8
+o
 hett

Fix test region names