<commit_before>/*******************************************************************************
 * Copyright (c) 2015 <NAME>.
 * 
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * and Eclipse Distribution License v1.0 which accompany this distribution.
 * 
 * The Eclipse Public License is available at
 *    http://www.eclipse.org/legal/epl-v10.html
 * and the Eclipse Distribution License is available at
 *    http://www.eclipse.org/org/documents/edl-v10.html.
 * 
 * Contributors:
 *     <NAME> - initial API and implementation
 *******************************************************************************/
package org.vaulttec.isis.script.tests.jvmmodel

import javax.inject.Inject
import org.eclipse.xtext.junit4.InjectWith
import org.eclipse.xtext.junit4.TemporaryFolder
import org.eclipse.xtext.junit4.XtextRunner
import org.eclipse.xtext.xbase.compiler.CompilationTestHelper
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.vaulttec.isis.script.tests.IsisInjectorProvider

@RunWith(typeof(XtextRunner))
@InjectWith(typeof(IsisInjectorProvider))
class IsisInferrerCompilerTest {

	@Rule @Inject public TemporaryFolder temporaryFolder
	@Inject extension CompilationTestHelper

	@Test
	def void testEmptyEntity() {
		'''
			package org.vaulttec.isis.script.test
			entity Entity1 {
			}
		'''.assertCompilesTo(
        '''
			package org.vaulttec.isis.script.test;
			
			import javax.inject.Inject;
			import org.apache.isis.applib.DomainObjectContainer;
			import org.apache.isis.applib.services.config.ConfigurationService;
			import org.apache.isis.applib.services.factory.FactoryService;
			import org.apache.isis.applib.services.message.MessageService;
			import org.apache.isis.applib.services.registry.ServiceRegistry2;
			import org.apache.isis.applib.services.repository.RepositoryService;
			import org.apache.isis.applib.services.title.TitleService;
			import org.apache.isis.applib.services.user.UserService;
			
			@SuppressWarnings("all")
			public class Entity1 implements Comparable<Entity1> {
			  @Inject
			  DomainObjectContainer container;
			  
			  @Inject
			  FactoryService factoryService;
			  
			  @Inject
			  ServiceRegistry2 serviceRegistry;
			  
			  @Inject
			  RepositoryService repositoryService;
			  
			  @Inject
			  TitleService titleService;
			  
			  @Inject
			  MessageService messageService;
			  
			  @Inject
			  ConfigurationService configService;
			  
			  @Inject
			  UserService userService;
			  
			  @Override
			  public int compareTo(final Entity1 other) {
			    return org.apache.isis.applib.util.ObjectContracts.compare(this, other);
			  }
			}
		''')
	}
	
	@Test
	def void testDerivedProperty() {
		'''
			package org.vaulttec.isis.script.test
			entity Entity1 {
			  property String prop1 {
			    derived {
			      "result"
			    }
			  }
			}
		'''.assertCompilesTo(
        '''
			package org.vaulttec.isis.script.test;
			
			import javax.inject.Inject;
			import org.apache.isis.applib.DomainObjectContainer;
			import org.apache.isis.applib.services.config.ConfigurationService;
			import org.apache.isis.applib.services.factory.FactoryService;
			import org.apache.isis.applib.services.message.MessageService;
			import org.apache.isis.applib.services.registry.ServiceRegistry2;
			import org.apache.isis.applib.services.repository.RepositoryService;
			import org.apache.isis.applib.services.title.TitleService;
			import org.apache.isis.applib.services.user.UserService;
			
			@SuppressWarnings("all")
			public class Entity1 implements Comparable<Entity1> {
			  @Inject
			  DomainObjectContainer container;
			  
			  @Inject
			  FactoryService factoryService;
			  
			  @Inject
			  ServiceRegistry2 serviceRegistry;
			  
			  @Inject
			  RepositoryService repositoryService;
			  
			  @Inject
			  TitleService titleService;
			  
			  @Inject
			  MessageService messageService;
			  
			  @Inject
			  ConfigurationService configService;
			  
			  @Inject
			  UserService userService;
			  
			  public String getProp1() {
			    return "result";
			  }
			  
			  @Override
			  public int compareTo(final Entity1 other) {
			    return org.apache.isis.applib.util.ObjectContracts.compare(this, other);
			  }
			}
		''')
	}

	@Test
	def void testEntityWithProperties() {
		'''
			package org.vaulttec.isis.script.test
			entity Child {
				property int prop1 {
					default {
						42
					}
					event Event1
				}
				property String prop2 {
					default {
						""
					}
					event Event2
				}
			}
		'''.assertCompilesTo(
		'''
			package org.vaulttec.isis.script.test;
			
			import javax.inject.Inject;
			import org.apache.isis.applib.DomainObjectContainer;
			import org.apache.isis.applib.services.config.ConfigurationService;
			import org.apache.isis.applib.services.eventbus.PropertyDomainEvent;
			import org.apache.isis.applib.services.factory.FactoryService;
			import org.apache.isis.applib.services.message.MessageService;
			import org.apache.isis.applib.services.registry.ServiceRegistry2;
			import org.apache.isis.applib.services.repository.RepositoryService;
			import org.apache.isis.applib.services.title.TitleService;
			import org.apache.isis.applib.services.user.UserService;
			
			@SuppressWarnings("all")
			public class Child implements Comparable<Child> {
			  @Inject
			  DomainObjectContainer container;
			  
			  @Inject
			  FactoryService factoryService;
			  
			  @Inject
			  ServiceRegistry2 serviceRegistry;
			  
			  @Inject
			  RepositoryService repositoryService;
			  
			  @Inject
			  TitleService titleService;
			  
			  @Inject
			  MessageService messageService;
			  
			  @Inject
			  ConfigurationService configService;
			  
			  @Inject
			  UserService userService;
			  
			  private int prop1;
			  
			  public int getProp1() {
			    return this.prop1;
			  }
			  <commit_msg>adds annotation to entity property test<commit_after>/*******************************************************************************
 * Copyright (c) 2015 <NAME>.
 * 
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * and Eclipse Distribution License v1.0 which accompany this distribution.
 * 
 * The Eclipse Public License is available at
 *    http://www.eclipse.org/legal/epl-v10.html
 * and the Eclipse Distribution License is available at
 *    http://www.eclipse.org/org/documents/edl-v10.html.
 * 
 * Contributors:
 *     <NAME> - initial API and implementation
 *******************************************************************************/
package org.vaulttec.isis.script.tests.jvmmodel

import javax.inject.Inject
import org.eclipse.xtext.junit4.InjectWith
import org.eclipse.xtext.junit4.TemporaryFolder
import org.eclipse.xtext.junit4.XtextRunner
import org.eclipse.xtext.xbase.compiler.CompilationTestHelper
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.vaulttec.isis.script.tests.IsisInjectorProvider

@RunWith(typeof(XtextRunner))
@InjectWith(typeof(IsisInjectorProvider))
class IsisInferrerCompilerTest {

	@Rule @Inject public TemporaryFolder temporaryFolder
	@Inject extension CompilationTestHelper

	@Test
	def void testEmptyEntity() {
		'''
			package org.vaulttec.isis.script.test
			entity Entity1 {
			}
		'''.assertCompilesTo(
        '''
			package org.vaulttec.isis.script.test;
			
			import javax.inject.Inject;
			import org.apache.isis.applib.DomainObjectContainer;
			import org.apache.isis.applib.services.config.ConfigurationService;
			import org.apache.isis.applib.services.factory.FactoryService;
			import org.apache.isis.applib.services.message.MessageService;
			import org.apache.isis.applib.services.registry.ServiceRegistry2;
			import org.apache.isis.applib.services.repository.RepositoryService;
			import org.apache.isis.applib.services.title.TitleService;
			import org.apache.isis.applib.services.user.UserService;
			
			@SuppressWarnings("all")
			public class Entity1 implements Comparable<Entity1> {
			  @Inject
			  DomainObjectContainer container;
			  
			  @Inject
			  FactoryService factoryService;
			  
			  @Inject
			  ServiceRegistry2 serviceRegistry;
			  
			  @Inject
			  RepositoryService repositoryService;
			  
			  @Inject
			  TitleService titleService;
			  
			  @Inject
			  MessageService messageService;
			  
			  @Inject
			  ConfigurationService configService;
			  
			  @Inject
			  UserService userService;
			  
			  @Override
			  public int compareTo(final Entity1 other) {
			    return org.apache.isis.applib.util.ObjectContracts.compare(this, other);
			  }
			}
		''')
	}
	
	@Test
	def void testDerivedProperty() {
		'''
			package org.vaulttec.isis.script.test
			entity Entity1 {
			  property String prop1 {
			    derived {
			      "result"
			    }
			  }
			}
		'''.assertCompilesTo(
        '''
			package org.vaulttec.isis.script.test;
			
			import javax.inject.Inject;
			import org.apache.isis.applib.DomainObjectContainer;
			import org.apache.isis.applib.services.config.ConfigurationService;
			import org.apache.isis.applib.services.factory.FactoryService;
			import org.apache.isis.applib.services.message.MessageService;
			import org.apache.isis.applib.services.registry.ServiceRegistry2;
			import org.apache.isis.applib.services.repository.RepositoryService;
			import org.apache.isis.applib.services.title.TitleService;
			import org.apache.isis.applib.services.user.UserService;
			
			@SuppressWarnings("all")
			public class Entity1 implements Comparable<Entity1> {
			  @Inject
			  DomainObjectContainer container;
			  
			  @Inject
			  FactoryService factoryService;
			  
			  @Inject
			  ServiceRegistry2 serviceRegistry;
			  
			  @Inject
			  RepositoryService repositoryService;
			  
			  @Inject
			  TitleService titleService;
			  
			  @Inject
			  MessageService messageService;
			  
			  @Inject
			  ConfigurationService configService;
			  
			  @Inject
			  UserService userService;
			  
			  public String getProp1() {
			    return "result";
			  }
			  
			  @Override
			  public int compareTo(final Entity1 other) {
			    return org.apache.isis.applib.util.ObjectContracts.compare(this, other);
			  }
			}
		''')
	}

	@Test
	def void testEntityWithProperties() {
		'''
			package org.vaulttec.isis.script.test
			entity Child {
				@org.apache.isis.applib.annotation.Property(
					domainEvent = org.apache.isis.applib.services.eventbus.PropertyDomainEvent.Default,
					editing = org.apache.isis.applib.annotation.Editing.DISABLED)
				property int prop1 {
					default {
						42
					}
					event Event1
				}
				property String prop2 {
					default {
						""
					}
					event Event2
				}
			}
		'''.assertCompilesTo(
		'''
			package org.vaulttec.isis.script.test;
			
			import javax.inject.Inject;
			import org.apache.isis.applib.DomainObjectContainer;
			import org.apache.isis.applib.annotation.Editing;
			import org.apache.isis.applib.annotation.Property;
			import org.apache.isis.applib.services.config.ConfigurationService;
			import org.apache.isis.applib.services.eventbus.PropertyDomainEvent;
			import org.apache.isis.applib.services.factory.FactoryService;
			import org.apache.isis.applib.services.message.MessageService;
			import org.apache.isis.applib.services.registry.ServiceRegistry2;
			import org.apache.isis.applib.services.repository.RepositoryService;
			import org.apache.isis.applib.services.title.TitleService;
			import org.apache.isis.applib.services.user.UserService;
			
			@SuppressWarnings("all")
			public class Child implements Comparable<Child> {
			  @Inject
			  DomainObjectContainer container;
			  
			  @Inject
			  FactoryService factoryService;
			  
			  @Inject
			  ServiceRegistry2 serviceRegistry;
			  
			  @Inject
			  RepositoryService repositoryService;
			  
			  @Inject
			  TitleService titleService;
			  
			  @Inject
			  MessageService messageService;
			  
			  @Inject
			  ConfigurationService configService;
			  
			  @Inject
			  UserService userService;
			  
			  private int prop1;
			  
			  @Property(domainEvent = PropertyDomainEvent.Default.class, editing = Editing.DISABLED)
			  public int getProp1() {
			    return this.prop1;
			  }
			  
{'fraction_non_alphanumeric': 0.10991935483870968, 'fraction_numerical': 0.0064516129032258064, 'mean_word_length': 3.1572242708682534, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2660279', 'n_tokens_mistral': 4574, 'n_tokens_neox': 3587, 'n_words': 654}