001/*
002 * Copyright 2011 Atteo.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
005 * in compliance with the License. You may obtain a copy of the License at
006 *
007 * http://www.apache.org/licenses/LICENSE-2.0
008 *
009 * Unless required by applicable law or agreed to in writing, software distributed under the License
010 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
011 * or implied. See the License for the specific language governing permissions and limitations under
012 * the License.
013 */
014package org.atteo.moonshine.services.assertions;
015
016import java.util.List;
017
018import javax.xml.bind.annotation.XmlElementRef;
019import javax.xml.bind.annotation.XmlRootElement;
020
021import org.atteo.moonshine.injection.InjectMembers;
022import org.atteo.moonshine.TopLevelService;
023
024/**
025 * Service which can be used to test for some conditions.
026 *
027 * <p>
028 * The purpose of this service is to help you debug your configuration
029 * file.
030 * </p>
031 *
032 * <p>
033 * Most of the {@link Assertion assertions} will fail the application
034 * startup when their requirement is not satisfied. There is also
035 * {@link EchoAssertion} which prints the specified content.
036 * </p>
037 */
038@XmlRootElement(name = "assertions")
039public class AssertionService extends TopLevelService {
040    /**
041     * List of assertions.
042     */
043    @InjectMembers
044    @XmlElementRef
045    private List<Assertion> assertions;
046
047    @Override
048    public void start() {
049        if (assertions == null) {
050            return;
051        }
052
053        for (Assertion assertion : assertions) {
054            assertion.check();
055        }
056    }
057}