001/*
002 * Copyright 2023 the original author or authors.
003 * <p>
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 * <p>
008 * https://www.apache.org/licenses/LICENSE-2.0
009 * <p>
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package de.cuioss.test.valueobjects.api.contracts;
017
018import java.lang.annotation.ElementType;
019import java.lang.annotation.Repeatable;
020import java.lang.annotation.Retention;
021import java.lang.annotation.RetentionPolicy;
022import java.lang.annotation.Target;
023import java.util.Collection;
024
025import de.cuioss.test.valueobjects.api.property.PropertyConfig;
026import de.cuioss.test.valueobjects.property.PropertyMetadata;
027import de.cuioss.test.valueobjects.property.util.AssertionStrategy;
028import de.cuioss.tools.property.PropertyMemberInfo;
029import de.cuioss.tools.property.PropertyReadWrite;
030
031/**
032 * If used on ValueObjectTest this test checks / tests factory-methods.
033 * <p>
034 * In order to define the arguments in the correct order you need to pass them
035 * using {@link #of()}
036 * </p>
037 * <p>
038 * As default it assumes the individual arguments to be optional, saying null is
039 * allowed. This can be controlled by {@link #required()}
040 * </p>
041 *
042 * @author Oliver Wolff
043 */
044@Retention(RetentionPolicy.RUNTIME)
045@Target({ ElementType.TYPE })
046@Repeatable(VerifyFactoryMethods.class)
047public @interface VerifyFactoryMethod {
048
049    /**
050     * @return the name of the factory method to be called
051     */
052    String factoryMethodName();
053
054    /**
055     * @return the (optional) type where the factory method is declared. If it is
056     *         not set it is assumed to be located at the actual type under test.
057     *         The default {@link VerifyFactoryMethod} acts as null value.
058     */
059    Class<?> enclosingType() default VerifyFactoryMethod.class;
060
061    /**
062     * @return an array of properties, identified by their names that are to be
063     *         considered for this test: Caution: The order of the names must
064     *         exactly match the order of the attributes of corresponding
065     *         constructor.
066     */
067    String[] of();
068
069    /**
070     * @return an array of properties, identified by their names that are to be
071     *         treated as required properties, see
072     *         {@link PropertyMetadata#isRequired()}. it is used
073     */
074    String[] required() default {};
075
076    /**
077     * @return an array of properties, identified by their names that are to be
078     *         treated as transient properties, see
079     *         {@link PropertyMemberInfo#TRANSIENT}
080     */
081    String[] transientProperties() default {};
082
083    /**
084     * @return an array of properties, identified by their names that are to be
085     *         treated as having a default values, see
086     *         {@link PropertyMetadata#isDefaultValue()}
087     */
088    String[] defaultValued() default {};
089
090    /**
091     * @return an array of properties, identified by their names that are to be
092     *         treated as being read-only, see {@link PropertyReadWrite#READ_ONLY},
093     *         usually used in conjunction with {@link #defaultValued()}
094     */
095    String[] readOnly() default {};
096
097    /**
098     * @return an array of properties, identified by their names that are to be
099     *         treated as being write-only, see
100     *         {@link PropertyReadWrite#WRITE_ONLY}, usually used in cases where a
101     *         property to be written will result in other properties but itself can
102     *         not be accessed directly
103     */
104    String[] writeOnly() default {};
105
106    /**
107     * @return an array of properties, identified by their names representing at
108     *         least a {@link Collection} that are to be asserted ignoring the
109     *         concrete order, see {@link PropertyConfig#assertionStrategy()} and
110     *         {@link AssertionStrategy#COLLECTION_IGNORE_ORDER}. The default
111     *         implementation will always respect / assert the same order of
112     *         elements.
113     */
114    String[] assertUnorderedCollection() default {};
115}