001: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
002:
003: This file is part of the db4o open source object database.
004:
005: db4o is free software; you can redistribute it and/or modify it under
006: the terms of version 2 of the GNU General Public License as published
007: by the Free Software Foundation and as clarified by db4objects' GPL
008: interpretation policy, available at
009: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
010: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
011: Suite 350, San Mateo, CA 94403, USA.
012:
013: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
014: WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: for more details.
017:
018: You should have received a copy of the GNU General Public License along
019: with this program; if not, write to the Free Software Foundation, Inc.,
020: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
021: package com.db4o.db4ounit.common.ta;
022:
023: import com.db4o.activation.*;
024: import com.db4o.config.*;
025: import com.db4o.diagnostic.*;
026: import com.db4o.internal.*;
027: import com.db4o.ta.*;
028:
029: import db4ounit.*;
030: import db4ounit.extensions.fixtures.*;
031: import db4ounit.extensions.util.*;
032:
033: public class TransparentActivationDiagnosticsTestCase extends
034: TransparentActivationTestCaseBase implements OptOutCS,
035: OptOutDefragSolo {
036:
037: public static class SomeTAAwareData {
038: public int _id;
039:
040: public SomeTAAwareData(int id) {
041: _id = id;
042: }
043: }
044:
045: public static class SomeOtherTAAwareData implements Activatable {
046: public SomeTAAwareData _data;
047:
048: public void bind(Activator activator) {
049: }
050:
051: public void activate() {
052: }
053:
054: public SomeOtherTAAwareData(SomeTAAwareData data) {
055: _data = data;
056: }
057: }
058:
059: public static class NotTAAwareData {
060: public SomeTAAwareData _data;
061:
062: public NotTAAwareData(SomeTAAwareData data) {
063: _data = data;
064: }
065: }
066:
067: private static class DiagnosticsRegistered {
068: public int _registeredCount = 0;
069: }
070:
071: private final DiagnosticsRegistered _registered = new DiagnosticsRegistered();
072: private final DiagnosticListener _checker;
073:
074: public TransparentActivationDiagnosticsTestCase() {
075: _checker = new DiagnosticListener() {
076: public void onDiagnostic(Diagnostic diagnostic) {
077: if (!(diagnostic instanceof NotTransparentActivationEnabled)) {
078: return;
079: }
080: NotTransparentActivationEnabled taDiagnostic = (NotTransparentActivationEnabled) diagnostic;
081: Assert.areEqual(CrossPlatformServices
082: .fullyQualifiedName(NotTAAwareData.class),
083: ((ClassMetadata) taDiagnostic.reason())
084: .getName());
085: _registered._registeredCount++;
086: }
087: };
088: }
089:
090: protected void configure(Configuration config) {
091: super .configure(config);
092: config.diagnostic().addListener(_checker);
093: }
094:
095: protected void db4oTearDownBeforeClean() throws Exception {
096: db().ext().configure().diagnostic().removeAllListeners();
097: super .db4oTearDownBeforeClean();
098: }
099:
100: public void testTADiagnostics() {
101: store(new SomeTAAwareData(1));
102: Assert.areEqual(0, _registered._registeredCount);
103: store(new SomeOtherTAAwareData(new SomeTAAwareData(2)));
104: Assert.areEqual(0, _registered._registeredCount);
105: store(new NotTAAwareData(new SomeTAAwareData(3)));
106: Assert.areEqual(1, _registered._registeredCount);
107: }
108:
109: public static void main(String[] args) {
110: new TransparentActivationDiagnosticsTestCase().runAll();
111: }
112: }
|