/**
 * Copyright (C) 2015 Red Hat, Inc.
 * <p>
 * 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
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * 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 io.fabric8.crd.generator;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

import io.fabric8.kubernetes.api.model.HasMetadata;
import io.fabric8.kubernetes.api.model.Namespaced;
import io.fabric8.kubernetes.client.CustomResource;
import io.fabric8.kubernetes.model.Scope;
import io.fabric8.kubernetes.model.annotation.Group;
import io.fabric8.kubernetes.model.annotation.ShortNames;
import io.fabric8.kubernetes.model.annotation.Version;
import org.junit.jupiter.api.Test;

public class CustomResourceInfoTest {

  public static class Spec {

  }

  public static class Status {

  }

  private static final String GROUP = "sample.fabric8.io";
  private static final String VERSION = "v1";

  @Group(GROUP)
  @Version(VERSION)
  @ShortNames("s")
  public static class ClusteredCR extends CustomResource<Spec, Status> {

  }

  @Group(GROUP)
  @Version(VERSION)
  public static class NamespacedCR extends CustomResource<Spec, Status> implements Namespaced {

  }

  @Test
  void shouldBeProperlyScoped() {
    CustomResourceInfo info = CustomResourceInfo.fromClass(ClusteredCR.class);
    assertEquals(GROUP, info.group());
    assertEquals(VERSION, info.version());
    assertEquals(Scope.CLUSTER, info.scope());

    info = CustomResourceInfo.fromClass(NamespacedCR.class);
    assertEquals(GROUP, info.group());
    assertEquals(VERSION, info.version());
    assertEquals(Scope.NAMESPACED, info.scope());
  }

  @Test
  void shouldProperlyCreateCustomResourceInfo() {
    CustomResourceInfo info = CustomResourceInfo.fromClass(ClusteredCR.class);
    assertEquals(GROUP, info.group());
    assertEquals(VERSION, info.version());
    assertEquals(Scope.CLUSTER, info.scope());
    assertEquals(ClusteredCR.class.getCanonicalName(), info.crClassName()); // todo: should we actually use the type name here?
    assertEquals(Spec.class.getTypeName(), info.specClassName().get());
    assertEquals(Status.class.getTypeName(), info.statusClassName().get());
    assertEquals(CustomResource.getSingular(ClusteredCR.class), info.singular());
    assertEquals(CustomResource.getPlural(ClusteredCR.class), info.plural());
    assertEquals(CustomResource.getCRDName(ClusteredCR.class), info.crdName());
    assertArrayEquals(CustomResource.getShortNames(ClusteredCR.class), info.shortNames());
    assertEquals(true, info.served());
    assertEquals(true, info.storage());
    assertEquals(HasMetadata.getKind(ClusteredCR.class), info.kind());
  }
}

@@ -35,20 +35,16 @@
  Inc.%0A *
- %3Cp%3E
 %0A * Lice
@@ -102,16 +102,19 @@
 cense%22);
+%0A *
  you may
@@ -138,19 +138,16 @@
 e except
-%0A *
  in comp
@@ -170,16 +170,19 @@
 License.
+%0A *
  You may
@@ -216,23 +216,27 @@
 se at%0A *
- %3Cp%3E%0A *
+%0A *        
  http://
@@ -277,12 +277,8 @@
 0%0A *
- %3Cp%3E
 %0A * 
@@ -344,16 +344,19 @@
 software
+%0A *
  distrib
@@ -377,19 +377,16 @@
  License
-%0A *
  is dist
@@ -413,16 +413,19 @@
 %22 BASIS,
+%0A *
  WITHOUT
@@ -477,19 +477,16 @@
  express
-%0A *
  or impl
@@ -489,16 +489,19 @@
 implied.
+%0A *
  See the
@@ -560,16 +560,19 @@
 ions and
+%0A *
  limitat
@@ -581,19 +581,16 @@
 ns under
-%0A *
  the Lic

format license