/**
   * Accuracy test for the method <code>getCommonProjectMetadataKeys()</code>.<br>
   * The result should be correct.
   *
   * @throws Exception to JUnit.
   */
  @Test
  public void test_getCommonProjectMetadataKeys_1() throws Exception {
    em.getTransaction().begin();
    instance.createProjectMetadataKey(projectMetadataKey, userId);
    em.getTransaction().commit();

    List<DirectProjectMetadataKey> res = instance.getCommonProjectMetadataKeys();

    assertEquals("'getCommonProjectMetadataKeys' should be correct.", 2, res.size());

    DirectProjectMetadataKey directProjectMetadataKey = res.get(0);
    if (directProjectMetadataKey.getId() != projectMetadataKey.getId()) {
      directProjectMetadataKey = res.get(1);
    }
    assertEquals(
        "'getCommonProjectMetadataKeys' should be correct.",
        "name3",
        directProjectMetadataKey.getName());
    assertEquals(
        "'getCommonProjectMetadataKeys' should be correct.",
        "some text",
        directProjectMetadataKey.getDescription());
    assertNull(
        "'getCommonProjectMetadataKeys' should be correct.",
        directProjectMetadataKey.getClientId());
    assertNull(
        "'getCommonProjectMetadataKeys' should be correct.",
        directProjectMetadataKey.getGrouping());
    assertTrue(
        "'getCommonProjectMetadataKeys' should be correct.", directProjectMetadataKey.isSingle());
  }
  /**
   * Accuracy test for the method <code>
   * saveProjectMetadataKey(DirectProjectMetadataKey projectMetadataKey,
   * long userId)</code>.<br>
   * The result should be correct.
   *
   * @throws Exception to JUnit.
   */
  @Test
  public void test_saveProjectMetadataKey_2() throws Exception {
    em.getTransaction().begin();
    instance.createProjectMetadataKey(projectMetadataKey, userId);
    em.getTransaction().commit();

    projectMetadataKey.setDescription("new description");
    projectMetadataKey.setPredefinedValues(new ArrayList<DirectProjectMetadataPredefinedValue>());
    em.getTransaction().begin();
    instance.saveProjectMetadataKey(projectMetadataKey, userId);
    em.getTransaction().commit();

    DirectProjectMetadataKey directProjectMetadataKey =
        em.find(DirectProjectMetadataKey.class, projectMetadataKey.getId());

    assertEquals(
        "'saveProjectMetadataKey' should be correct.", "name3", directProjectMetadataKey.getName());
    assertEquals(
        "'saveProjectMetadataKey' should be correct.",
        "new description",
        directProjectMetadataKey.getDescription());
    assertNull(
        "'saveProjectMetadataKey' should be correct.", directProjectMetadataKey.getClientId());
    assertNull(
        "'saveProjectMetadataKey' should be correct.", directProjectMetadataKey.getGrouping());
    assertTrue("'saveProjectMetadataKey' should be correct.", directProjectMetadataKey.isSingle());
  }
  /**
   * Accuracy test for the method <code>deleteProjectMetadataKey(long projectMetadataKeyId,
   * long userId)</code>.<br>
   * The result should be correct.
   *
   * @throws Exception to JUnit.
   */
  @Test
  public void test_deleteProjectMetadataKey() throws Exception {
    instance.createProjectMetadataKey(projectMetadataKey, userId);

    instance.deleteProjectMetadataKey(projectMetadataKey.getId(), userId);

    assertNull(
        "'deleteProjectMetadataKey' should be correct.",
        em.find(DirectProjectMetadataKey.class, projectMetadataKey.getId()));
  }
  /**
   * Accuracy test for the method <code>getProjectMetadataKey(long projectMetadataKeyId)</code>.<br>
   * The result should be correct.
   *
   * @throws Exception to JUnit.
   */
  @Test
  public void test_getProjectMetadataKey_1() throws Exception {
    instance.createProjectMetadataKey(projectMetadataKey, userId);

    DirectProjectMetadataKey res = instance.getProjectMetadataKey(projectMetadataKey.getId());

    assertEquals("'getProjectMetadataKey' should be correct.", "name3", res.getName());
    assertEquals("'getProjectMetadataKey' should be correct.", "some text", res.getDescription());
    assertNull("'getProjectMetadataKey' should be correct.", res.getClientId());
    assertNull("'getProjectMetadataKey' should be correct.", res.getGrouping());
    assertTrue("'getProjectMetadataKey' should be correct.", res.isSingle());
  }
  /**
   * Accuracy test for the method <code>
   * createProjectMetadataKey(DirectProjectMetadataKey projectMetadataKey,
   * long userId)</code>.<br>
   * The result should be correct.
   *
   * @throws Exception to JUnit.
   */
  @Test
  public void test_createProjectMetadataKey_1() throws Exception {
    em.getTransaction().begin();
    instance.createProjectMetadataKey(projectMetadataKey, userId);
    em.getTransaction().commit();

    DirectProjectMetadataKey directProjectMetadataKey =
        em.find(DirectProjectMetadataKey.class, projectMetadataKey.getId());
    DirectProjectMetadataKeyAudit directProjectMetadataKeyAudit =
        em.find(DirectProjectMetadataKeyAudit.class, 1L);

    assertEquals(
        "'createProjectMetadataKey' should be correct.",
        "name3",
        directProjectMetadataKey.getName());
    assertEquals(
        "'createProjectMetadataKey' should be correct.",
        "some text",
        directProjectMetadataKey.getDescription());
    assertNull(
        "'createProjectMetadataKey' should be correct.", directProjectMetadataKey.getClientId());
    assertNull(
        "'createProjectMetadataKey' should be correct.", directProjectMetadataKey.getGrouping());
    assertTrue(
        "'createProjectMetadataKey' should be correct.", directProjectMetadataKey.isSingle());

    assertEquals(
        "'createProjectMetadataKey' should be correct.",
        projectMetadataKey.getId(),
        directProjectMetadataKeyAudit.getProjectMetadataKeyId());
    assertEquals(
        "'createProjectMetadataKey' should be correct.",
        "name3",
        directProjectMetadataKeyAudit.getName());
    assertEquals(
        "'createProjectMetadataKey' should be correct.",
        "some text",
        directProjectMetadataKeyAudit.getDescription());
    assertNull(
        "'createProjectMetadataKey' should be correct.",
        directProjectMetadataKeyAudit.getClientId());
    assertNull(
        "'createProjectMetadataKey' should be correct.",
        directProjectMetadataKeyAudit.getGrouping());
    assertTrue(
        "'createProjectMetadataKey' should be correct.", directProjectMetadataKeyAudit.isSingle());
    assertEquals(
        "'createProjectMetadataKey' should be correct.",
        1L,
        directProjectMetadataKeyAudit.getActionUserId());
  }
  /**
   * Accuracy test for the method <code>
   * createProjectMetadataKey(DirectProjectMetadataKey projectMetadataKey,
   * long userId)</code>.<br>
   * The result should be correct.
   *
   * @throws Exception to JUnit.
   */
  @Test
  public void test_createProjectMetadataKey_2() throws Exception {
    List<DirectProjectMetadataPredefinedValue> predefinedValues =
        new ArrayList<DirectProjectMetadataPredefinedValue>();
    DirectProjectMetadataPredefinedValue predefinedValue =
        new DirectProjectMetadataPredefinedValue();
    predefinedValue.setPosition(1);
    predefinedValue.setPredefinedMetadataValue("value");
    predefinedValue.setProjectMetadataKey(projectMetadataKey);
    predefinedValues.add(predefinedValue);
    projectMetadataKey.setPredefinedValues(predefinedValues);

    em.getTransaction().begin();
    instance.createProjectMetadataKey(projectMetadataKey, userId);
    em.getTransaction().commit();

    DirectProjectMetadataPredefinedValueAudit directProjectMetadataPredefinedValueAudit =
        em.find(DirectProjectMetadataPredefinedValueAudit.class, 1L);

    assertEquals(
        "'createProjectMetadataKey' should be correct.",
        projectMetadataKey.getId(),
        directProjectMetadataPredefinedValueAudit.getProjectMetadataKeyId());
    assertEquals(
        "'createProjectMetadataKey' should be correct.",
        1,
        directProjectMetadataPredefinedValueAudit.getPosition());
    assertEquals(
        "'createProjectMetadataKey' should be correct.",
        "value",
        directProjectMetadataPredefinedValueAudit.getPredefinedMetadataValue());
    assertEquals(
        "'createProjectMetadataKey' should be correct.",
        1L,
        directProjectMetadataPredefinedValueAudit.getActionUserId());
  }
  /**
   * Failure test for the method <code>
   * createProjectMetadataKey(DirectProjectMetadataKey projectMetadataKey,
   * long userId)</code> with entity fails the validation.<br>
   * <code>ValidationException</code> is expected.
   *
   * @throws Exception to JUnit.
   */
  @Test(expected = ValidationException.class)
  public void test_createProjectMetadataKey_ValidationError() throws Exception {
    projectMetadataKey.setClientId(1L);

    instance.createProjectMetadataKey(projectMetadataKey, userId);
  }
  /**
   * Failure test for the method <code>
   * createProjectMetadataKey(DirectProjectMetadataKey projectMetadataKey,
   * long userId)</code> with projectMetadataKey is <code>null</code>.<br>
   * <code>IllegalArgumentException</code> is expected.
   *
   * @throws Exception to JUnit.
   */
  @Test(expected = IllegalArgumentException.class)
  public void test_createProjectMetadataKey_projectMetadataKeyNull() throws Exception {
    projectMetadataKey = null;

    instance.createProjectMetadataKey(projectMetadataKey, userId);
  }