-
Notifications
You must be signed in to change notification settings - Fork 308
/
AbstractITextConfigurationEventTest.cs
144 lines (126 loc) · 6.46 KB
/
AbstractITextConfigurationEventTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2024 Apryse Group NV
Authors: Apryse Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using iText.Commons.Actions.Confirmations;
using iText.Commons.Actions.Data;
using iText.Commons.Actions.Processors;
using iText.Commons.Actions.Sequence;
using iText.Test;
namespace iText.Commons.Actions {
[NUnit.Framework.Category("UnitTest")]
public class AbstractITextConfigurationEventTest : ExtendedITextTest {
[NUnit.Framework.TearDown]
public virtual void After() {
ProductEventHandler.INSTANCE.ClearProcessors();
}
[NUnit.Framework.Test]
public virtual void AddProcessorTest() {
AbstractITextConfigurationEvent @event = new AbstractITextConfigurationEventTest.TestAbstractITextConfigurationEvent
();
ITextProductEventProcessor processor = new AbstractITextConfigurationEventTest.TestITextProductEventProcessor
();
@event.AddProcessor(processor);
IDictionary<String, ITextProductEventProcessor> processors = ProductEventHandler.INSTANCE.GetProcessors();
NUnit.Framework.Assert.AreEqual(1, processors.Count);
NUnit.Framework.Assert.IsTrue(processors.Values.Contains(processor));
}
[NUnit.Framework.Test]
public virtual void GetProcessorsTest() {
AbstractITextConfigurationEvent @event = new AbstractITextConfigurationEventTest.TestAbstractITextConfigurationEvent
();
ITextProductEventProcessor processor = new AbstractITextConfigurationEventTest.TestITextProductEventProcessor
();
@event.AddProcessor(processor);
NUnit.Framework.Assert.AreEqual(ProductEventHandler.INSTANCE.GetProcessors(), @event.GetProcessors());
}
[NUnit.Framework.Test]
public virtual void RemoveProcessorTest() {
AbstractITextConfigurationEvent @event = new AbstractITextConfigurationEventTest.TestAbstractITextConfigurationEvent
();
ITextProductEventProcessor processor = new AbstractITextConfigurationEventTest.TestITextProductEventProcessor
();
@event.AddProcessor(processor);
@event.RemoveProcessor(processor.GetProductName());
IDictionary<String, ITextProductEventProcessor> processors = ProductEventHandler.INSTANCE.GetProcessors();
NUnit.Framework.Assert.AreEqual(0, processors.Count);
}
[NUnit.Framework.Test]
public virtual void GetActiveProcessorTest() {
AbstractITextConfigurationEvent @event = new AbstractITextConfigurationEventTest.TestAbstractITextConfigurationEvent
();
ITextProductEventProcessor processor = new AbstractITextConfigurationEventTest.TestITextProductEventProcessor
();
@event.AddProcessor(processor);
NUnit.Framework.Assert.AreEqual(processor, @event.GetActiveProcessor(processor.GetProductName()));
}
[NUnit.Framework.Test]
public virtual void AddEventTest() {
AbstractITextConfigurationEvent configurationEvent = new AbstractITextConfigurationEventTest.TestAbstractITextConfigurationEvent
();
AbstractProductProcessITextEvent processEvent = new AbstractITextConfigurationEventTest.TestAbstractProductProcessITextEvent
();
SequenceId id = new SequenceId();
configurationEvent.AddEvent(id, processEvent);
IList<AbstractProductProcessITextEvent> events = ProductEventHandler.INSTANCE.GetEvents(id);
NUnit.Framework.Assert.AreEqual(1, events.Count);
NUnit.Framework.Assert.AreEqual(processEvent, events[0]);
}
[NUnit.Framework.Test]
public virtual void GetEventsTest() {
AbstractITextConfigurationEvent configurationEvent = new AbstractITextConfigurationEventTest.TestAbstractITextConfigurationEvent
();
SequenceId id = new SequenceId();
configurationEvent.AddEvent(id, new AbstractITextConfigurationEventTest.TestAbstractProductProcessITextEvent
());
configurationEvent.AddEvent(id, new AbstractITextConfigurationEventTest.TestAbstractProductProcessITextEvent
());
NUnit.Framework.Assert.AreEqual(ProductEventHandler.INSTANCE.GetEvents(id), configurationEvent.GetEvents(id
));
}
internal class TestAbstractITextConfigurationEvent : AbstractITextConfigurationEvent {
protected internal override void DoAction() {
}
// Empty method.
}
internal class TestAbstractProductProcessITextEvent : AbstractProductProcessITextEvent {
public TestAbstractProductProcessITextEvent()
: base(new SequenceId(), new ProductData("test public product name", "test product name", "test version",
0, 1), null, EventConfirmationType.ON_DEMAND) {
}
public override String GetEventType() {
return "test event type";
}
}
internal class TestITextProductEventProcessor : ITextProductEventProcessor {
public virtual void OnEvent(AbstractProductProcessITextEvent @event) {
}
// Empty method.
public virtual String GetProductName() {
return "test product";
}
public virtual String GetUsageType() {
return "test usage type";
}
public virtual String GetProducer() {
return "test producer";
}
}
}
}