// Path: src/main/java/com/synopsys/arc/jenkinsci/plugins/jobrestrictions/nodes/JobRestrictionProperty.java
// public class JobRestrictionProperty extends NodeProperty<Node> {
// 
//     /**Restriction according to buildable item requirements*/
//     JobRestriction jobRestriction;
// 
//     @DataBoundConstructor
//     public JobRestrictionProperty(JobRestriction jobRestriction) {
//         this.jobRestriction = jobRestriction;
//     }
//     
//     @Override
//     public CauseOfBlockage canTake(Queue.BuildableItem item) {
//         if (jobRestriction != null) {
//             if (!jobRestriction.canTake(item)) {
//                 return JobRestrictionBlockageCause.DEFAULT;
//             }
//         }
//         
//         // Can take
//         return null; 
//     }
// 
//     public JobRestriction getJobRestriction() {
//         return jobRestriction;
//     }
//          
//     @Extension
//     public static class DescriptorImpl extends NodePropertyDescriptor {
//         @Override
//         public String getDisplayName() {
//             return Messages.nodes_JobRestrictionProperty_DisplayName();
//         } 
//     }
// }
// 
// Path: src/main/java/io/jenkins/plugins/jobrestrictions/util/ClassSelector.java
// public class ClassSelector implements Describable<ClassSelector>, Serializable {
//     
//     /**ID of the user*/
//     final @CheckForNull String selectedClass;
// 
//     @DataBoundConstructor
//     public ClassSelector(@CheckForNull String selectedClass) {
//         this.selectedClass = hudson.Util.fixEmptyAndTrim(selectedClass);
//     }
// 
//     @CheckForNull
//     public String getSelectedClass() {
//         return selectedClass;
//     }
// 
//     @Override
//     public Descriptor<ClassSelector> getDescriptor() {
//         return DESCRIPTOR;
//     }
// 
//     @Override
//     public boolean equals(Object obj) {       
//         if (obj instanceof ClassSelector) {
//             ClassSelector cmp = (ClassSelector)obj;
//             return selectedClass != null ? selectedClass.equals(cmp.selectedClass) : cmp.selectedClass == null;
//         }           
//         return false;    
//     }
// 
//     @Override
//     public int hashCode() {
//         int hash = 7;
//         hash = 17 * hash + (selectedClass != null ? selectedClass.hashCode() : 0);
//         return hash;
//     }
//           
//     @Extension
//     public static final DescriptorImpl DESCRIPTOR = new DescriptorImpl();
//     public static class DescriptorImpl extends Descriptor<ClassSelector> {
//         
//         @Override
//         public String getDisplayName() {
//             return "N/A";
//         }
//         
//         public FormValidation doCheckSelectedClass(final @QueryParameter String selectedClass) {
//             String _selectedClass = Util.fixEmptyAndTrim(selectedClass);
//             if (_selectedClass == null) {
//                 return FormValidation.error("Field is empty");
//             }
// 
//             try {
//                 Jenkins.getInstance().getPluginManager().uberClassLoader.loadClass(_selectedClass);
//             } catch (Exception ex) {
//                 return FormValidation.warning("Class " + _selectedClass + " cannot be resolved: " + ex.toString());
//             }
// 
//             return FormValidation.ok();
//         }
//     }
// }


import java.util.Calendar;
import java.util.Collections;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.assertThat;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
import com.synopsys.arc.jenkinsci.plugins.jobrestrictions.nodes.JobRestrictionProperty;
import io.jenkins.plugins.jobrestrictions.util.ClassSelector;
import hudson.matrix.MatrixProject;
import hudson.model.Action;
import hudson.model.Queue;
import hudson.model.FreeStyleProject;
import java.util.Arrays;
/*
 * The MIT License
 *
 * Copyright (c) 2016 Oleg Nenashev.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package io.jenkins.plugins.jobrestrictions.restrictions.job;


/**
 * Tests of {@link JobClassNameRestriction}.
 * @author Oleg Nenashev
 */
@Issue("JENKINS-38644")
public class JobClassNameRestrictionTest {
    
    @Rule
    public JenkinsRule j = new JenkinsRule();
    
    @Test
    public void shouldRestrictJobClass() throws Exception {
        JobClassNameRestriction jobClassNameRestriction = new JobClassNameRestriction(
                Arrays.asList(new ClassSelector(FreeStyleProject.class.getName())));
// Path: src/main/java/com/synopsys/arc/jenkinsci/plugins/jobrestrictions/nodes/JobRestrictionProperty.java
// public class JobRestrictionProperty extends NodeProperty<Node> {
// 
//     /**Restriction according to buildable item requirements*/
//     JobRestriction jobRestriction;
// 
//     @DataBoundConstructor
//     public JobRestrictionProperty(JobRestriction jobRestriction) {
//         this.jobRestriction = jobRestriction;
//     }
//     
//     @Override
//     public CauseOfBlockage canTake(Queue.BuildableItem item) {
//         if (jobRestriction != null) {
//             if (!jobRestriction.canTake(item)) {
//                 return JobRestrictionBlockageCause.DEFAULT;
//             }
//         }
//         
//         // Can take
//         return null; 
//     }
// 
//     public JobRestriction getJobRestriction() {
//         return jobRestriction;
//     }
//          
//     @Extension
//     public static class DescriptorImpl extends NodePropertyDescriptor {
//         @Override
//         public String getDisplayName() {
//             return Messages.nodes_JobRestrictionProperty_DisplayName();
//         } 
//     }
// }
// 
// Path: src/main/java/io/jenkins/plugins/jobrestrictions/util/ClassSelector.java
// public class ClassSelector implements Describable<ClassSelector>, Serializable {
//     
//     /**ID of the user*/
//     final @CheckForNull String selectedClass;
// 
//     @DataBoundConstructor
//     public ClassSelector(@CheckForNull String selectedClass) {
//         this.selectedClass = hudson.Util.fixEmptyAndTrim(selectedClass);
//     }
// 
//     @CheckForNull
//     public String getSelectedClass() {
//         return selectedClass;
//     }
// 
//     @Override
//     public Descriptor<ClassSelector> getDescriptor() {
//         return DESCRIPTOR;
//     }
// 
//     @Override
//     public boolean equals(Object obj) {       
//         if (obj instanceof ClassSelector) {
//             ClassSelector cmp = (ClassSelector)obj;
//             return selectedClass != null ? selectedClass.equals(cmp.selectedClass) : cmp.selectedClass == null;
//         }           
//         return false;    
//     }
// 
//     @Override
//     public int hashCode() {
//         int hash = 7;
//         hash = 17 * hash + (selectedClass != null ? selectedClass.hashCode() : 0);
//         return hash;
//     }
//           
//     @Extension
//     public static final DescriptorImpl DESCRIPTOR = new DescriptorImpl();
//     public static class DescriptorImpl extends Descriptor<ClassSelector> {
//         
//         @Override
//         public String getDisplayName() {
//             return "N/A";
//         }
//         
//         public FormValidation doCheckSelectedClass(final @QueryParameter String selectedClass) {
//             String _selectedClass = Util.fixEmptyAndTrim(selectedClass);
//             if (_selectedClass == null) {
//                 return FormValidation.error("Field is empty");
//             }
// 
//             try {
//                 Jenkins.getInstance().getPluginManager().uberClassLoader.loadClass(_selectedClass);
//             } catch (Exception ex) {
//                 return FormValidation.warning("Class " + _selectedClass + " cannot be resolved: " + ex.toString());
//             }
// 
//             return FormValidation.ok();
//         }
//     }
// }


// Path: src/test/java/io/jenkins/plugins/jobrestrictions/restrictions/job/JobClassNameRestrictionTest.java
import java.util.Calendar;
import java.util.Collections;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.assertThat;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
import com.synopsys.arc.jenkinsci.plugins.jobrestrictions.nodes.JobRestrictionProperty;
import io.jenkins.plugins.jobrestrictions.util.ClassSelector;
import hudson.matrix.MatrixProject;
import hudson.model.Action;
import hudson.model.Queue;
import hudson.model.FreeStyleProject;
import java.util.Arrays;

/*
 * The MIT License
 *
 * Copyright (c) 2016 Oleg Nenashev.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package io.jenkins.plugins.jobrestrictions.restrictions.job;


/**
 * Tests of {@link JobClassNameRestriction}.
 * @author Oleg Nenashev
 */
@Issue("JENKINS-38644")
public class JobClassNameRestrictionTest {
    
    @Rule
    public JenkinsRule j = new JenkinsRule();
    
    @Test
    public void shouldRestrictJobClass() throws Exception {
        JobClassNameRestriction jobClassNameRestriction = new JobClassNameRestriction(
                Arrays.asList(new ClassSelector(FreeStyleProject.class.getName())));
        JobRestrictionProperty prop = new JobRestrictionProperty(jobClassNameRestriction);