mirror of
https://github.com/google/nomulus.git
synced 2025-07-09 12:43:24 +02:00
Add a test to verify persistence.xml (#482)
This commit is contained in:
parent
f134c4bf37
commit
90945bcc30
2 changed files with 67 additions and 6 deletions
|
@ -25,17 +25,11 @@
|
|||
<class>google.registry.schema.domain.RegistryLock</class>
|
||||
<class>google.registry.schema.tmch.ClaimsList</class>
|
||||
<class>google.registry.schema.cursor.Cursor</class>
|
||||
<class>google.registry.model.transfer.BaseTransferObject</class>
|
||||
<class>google.registry.schema.tld.PremiumList</class>
|
||||
<class>google.registry.schema.tld.PremiumEntry</class>
|
||||
<class>google.registry.schema.tld.ReservedList</class>
|
||||
<class>google.registry.model.domain.secdns.DelegationSignerData</class>
|
||||
<class>google.registry.model.domain.DesignatedContact</class>
|
||||
<class>google.registry.model.domain.DomainBase</class>
|
||||
<class>google.registry.model.domain.GracePeriod</class>
|
||||
<class>org.joda.time.Period</class>
|
||||
<class>google.registry.model.transfer.TransferData</class>
|
||||
<class>google.registry.model.eppcommon.Trid</class>
|
||||
|
||||
<!-- Customized type converters -->
|
||||
<class>google.registry.persistence.BloomFilterConverter</class>
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
// Copyright 2020 The Nomulus Authors. All Rights Reserved.
|
||||
//
|
||||
// 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 google.registry.persistence;
|
||||
|
||||
import static com.google.common.collect.ImmutableList.toImmutableList;
|
||||
import static com.google.common.collect.ImmutableSet.toImmutableSet;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.truth.Expect;
|
||||
import java.util.Collections;
|
||||
import javax.persistence.AttributeConverter;
|
||||
import javax.persistence.Entity;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
/** Unit tests to verify persistence.xml is valid. */
|
||||
@RunWith(JUnit4.class)
|
||||
public class PersistenceXmlTest {
|
||||
|
||||
@ClassRule public static final Expect expect = Expect.create();
|
||||
|
||||
@Test
|
||||
public void verifyClassTags_containOnlyRequiredClasses() {
|
||||
ImmutableList<Class> managedClassed = PersistenceXmlUtility.getManagedClasses();
|
||||
|
||||
ImmutableList<Class> unnecessaryClasses =
|
||||
managedClassed.stream()
|
||||
.filter(
|
||||
clazz ->
|
||||
!clazz.isAnnotationPresent(Entity.class)
|
||||
&& !AttributeConverter.class.isAssignableFrom(clazz))
|
||||
.collect(toImmutableList());
|
||||
|
||||
ImmutableSet<Class> duplicateClasses =
|
||||
managedClassed.stream()
|
||||
.filter(clazz -> Collections.frequency(managedClassed, clazz) > 1)
|
||||
.collect(toImmutableSet());
|
||||
|
||||
expect
|
||||
.withMessage("Found duplicate <class> tags defined in persistence.xml.")
|
||||
.that(duplicateClasses)
|
||||
.isEmpty();
|
||||
|
||||
expect
|
||||
.withMessage(
|
||||
"Found unnecessary <class> tags defined in persistence.xml. Only entity class and"
|
||||
+ " implementation of AttributeConverter are required to be added in"
|
||||
+ " persistence.xml.")
|
||||
.that(unnecessaryClasses)
|
||||
.isEmpty();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue