Skip to content

Commit

Permalink
Initialize NSArray key operators defined by Wonder before test execut…
Browse files Browse the repository at this point in the history
…ion (closes #33)
  • Loading branch information
hprange committed Feb 21, 2014
1 parent 96041e7 commit dcb85fc
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import er.extensions.ERXExtensions;
import er.extensions.eof.ERXEC;
import er.extensions.eof.ERXEntityClassDescription;
import er.extensions.foundation.ERXArrayUtilities;
import er.extensions.foundation.ERXProperties;

/**
Expand Down Expand Up @@ -100,8 +101,8 @@ public void insert(EOEnterpriseObject object) {

// Simulate what ERExtensions does
EOModelGroup.setClassDelegate(SINGLETONS.exrExtensions);

ERXEntityClassDescription.registerDescription();
ERXArrayUtilities.initialize();

for (String modelName : modelNames) {
loadModel(modelName);
Expand Down
50 changes: 50 additions & 0 deletions src/test/java/com/wounit/rules/TestNSArrayOperators.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* Copyright (C) 2009 hprange <hprange@gmail.com>
*
* 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 com.wounit.rules;

import static org.junit.Assert.assertThat;
import static org.junit.matchers.JUnitMatchers.hasItems;

import java.math.BigDecimal;

import org.junit.Rule;
import org.junit.Test;

import com.webobjects.foundation.NSArray;
import com.wounit.annotations.Dummy;
import com.wounit.model.ExtendedPrototypeEntity;

/**
* @author <a href="mailto:hprange@gmail.com.br">Henrique Prange</a>
*/
public class TestNSArrayOperators {
@Rule
public MockEditingContext editingContext = new MockEditingContext("Test");

@Dummy(size = 2)
private NSArray<ExtendedPrototypeEntity> entities;

@Test
public void supportNSArrayOperators() throws Exception {
entities.get(0).setExtendedAttribute(BigDecimal.TEN);
entities.get(1).setExtendedAttribute(BigDecimal.ONE);

@SuppressWarnings("unchecked")
NSArray<BigDecimal> result = (NSArray<BigDecimal>) entities.valueForKeyPath("@flatten." + ExtendedPrototypeEntity.EXTENDED_ATTRIBUTE_KEY);

assertThat(result, hasItems(BigDecimal.TEN, BigDecimal.ONE));
}
}

0 comments on commit dcb85fc

Please sign in to comment.